> 2009/05/27 (水) 22:41:18 ◆ ▼ ◇ [qwerty]> > 同じ数字を何度も使ってもいいんだよね?(;´Д`)もちろん整数だよね?500個ちょうど使うんだよね?
> ごめんなさい(;´Д`)1,2,3,3,4と4個であれば、1は一回のみ、3は2回使えます
> 勿論数字は全て整数で0~500個までの個数があります
#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個程度でも結構気が遠くなる時間がかかりそうな気がするな(;´Д`)
参考:2009/05/27(水)22時28分19秒