寫出一個可以工作的程序并不夠
最簡單的是窮舉,不過那可要O(9*109),不可取
posted on 2007-04-16 17:29 Dain 閱讀(1119) 評論(5) 編輯 收藏 引用 所屬分類: 算法 、筆記
#include<ctime> #include<iostream> using namespace std; int cnt=0; void dfs(int s,int i){ if(i>9){ cout<<s<<endl; cnt++; return; } s*=10; int m=s%i; if(m!=0) m=i-m; for(; m<10; m+=i) dfs(s+m,i+1); } int main(){ for(int j=0; j<10000;++j){ cnt=0; for(int i=1; i<10; ++i) dfs(i,2); // cout<<cnt<<endl; } cout<<clock(); return 0; } 答案有2492個,不計輸出用時約0.00058秒 回復 更多評論
組合數學內容,早知道它很有用,可是還是忘記的差不多了,唉... 回復 更多評論
我做出來是2227個 回復 更多評論
是我看錯了,是2492個 回復 更多評論
看下你的算法 @wzqxp2002 回復 更多評論
Powered by: C++博客 Copyright © Dain