- 论坛徽章:
- 0
|
前面看到有版友提出来的,这里发一下Code,请指教 
#include <stdio.h>
int stk[7];
int flag[37]; //set flag[x] to 1 will forbid x to be selected
int total=0;
int printStk()
{
int i, cnt=0;
total++;
printf("total(%d)=>[", total);
for(i=0; i<7; i++)
{
printf("%d-", stk);
cnt += stk;
}
printf("] = %d\n", cnt);
return 0;
}
int try()
{
int i=1, step=0, sum=0;
while(!(step==0 && i==37))
{
if(i==37)
{
step--;
sum -= stk[step];
i = stk[step] + 1;
flag[stk[step]] = 0;
stk[step] = 0;
continue;
}
if(step == 7)
{
//step up
step--;
sum -= stk[step];
i = stk[step] + 1;
flag[stk[step]] = 0;
continue;
}
if( flag == 0)
{
sum += i;
stk[step] = i;
flag = 1;
if(step == 6)
{
if ((sum <500)&&(sum>200))
{
printStk();
}
}
//step down
step++;
i = 1;
}else{
//step right
i++;
}
}
}
int main()
{
try();
return 0;
} |
|