> 2009/05/27 (水) 22:49:55 ◆ ▼ ◇ [qwerty]> >
> > #include "stdafx.h"
> > #include <stdlib.h>
> > #include <string>
> > __int64 table[]={1,5,3,2,8,4,9,0,1,2,3,4,1,5,3,2,8,4,9,0,1,2,3,4};
> > int ntable = sizeof(table)/sizeof(__int64);
> >
> > __int64 func( std::string &str, __int64 total, __int64 *tbl, int ntbl)
> > {
> > for(int i=0;i<ntbl; ++i){
> > std::string s = str+",";
> > char buf[0x40];
> > _ltoa_s((long)tbl[i],buf,0x40,10);
> > s += buf;
> > if( total+tbl[i]==9){
> > printf("みつけたよ(%s)\n", s.c_str());
> > } else {
> > func( s, total+tbl[i], &tbl[i+1], (ntbl-(i+1) ) );
> > }
> > }
> > return total;
> > }
> > int _tmain(int argc, _TCHAR* argv[])
> > {
> > std::string str;
> > func(str, 0, table, ntable);
> > return 0;
> > }
> > とりあえずでかい数字を扱えるようにはしてみたが500個程度でも結構気が遠くなる時間がかかりそうな気がするな(;´Д`)
> 工学博士の俺が来たよ
> この問題は組み合わせ最適化問題の範疇に入ると思う
> NP完全なのでどう頑張っても多項式オーダーで解くのは無理だよ
まあ合計いくらなんである合計数値を超えたら探索やめる、とかでもだいぶ減るだろうね(;´Д`)そのあたりは勝手に工夫してやってもらいたい
参考:2009/05/27(水)22時48分04秒