hdu1226 超級密碼 bfs

2021-06-13 20:31:19 字數 673 閱讀 4385

思路:

因為n <= 5000 ,所以方案個數也只有5000個,可以用bfs來做。。一開始挺糾結怎麼做,但是上網一看別的大牛的**,一下子就恍然大悟豁然開朗,如同撥開雲霧見青天~~~^o^~~~~

**:#include #include #include #include using namespace std;

const int maxn = 20;

const int maxm = 5100;

const int inf = (0x7f7f7f7f);

int n, c, t, m;

bool jud[maxn];

bool vis[maxm];

int flag;

struct node

;string res;

queueq;

void init()

void bfs()

} while (!q.empty())

else

}for (i=0; i<16; i++)

}} }

}int main()

if (n == 0)

bfs();

if (flag == -1)

puts("give me the bomb please");

else

cout<

HDU1226 超級密碼 BFS

由於n最大也只有5000,則對於列舉的密碼s,s n的狀態也只有5000種。所以每乙個列舉到的狀態,開兩個內容,乙個表示密碼的字串,乙個表示模n的餘數,當餘數為0的時候,說明找到密碼。include include include include include using namespace st...

hdu 1226 超級密碼 bfs

c 超級密碼 time limit 10000msmemory limit 32768kb64bit io format i64d i64u submit status description ignatius花了乙個星期的時間終於找到了傳說中的寶藏,寶藏被放在乙個房間裡,房間的門用密碼鎖起來了,在...

HDU1226 超級密碼(BFS)

題目大意 求乙個數,它是由m個數字組成,是c進製,且是n 10進製整數 的整數倍。求這個數的最小值。例如n 22,c 10,m 3,三個數字是7,0,1 那麼滿足由7,0,1組成的10進製數且是22的倍數的最小值是110。由於求的數是最小的,用bfs比dfs更好一些。用bfs實現由數字組成的數按從小...