#include "stdio.h"
int data[]={4816,4776,4498,4616,4948,4684,4710,5266,4760,5168,4770,5134,5076,4784,
5174,4732,4782,4746,4730,5224,5164,4742,4724,4730,4762,4162,4188,4830,4942,4072,
4270,4520,4808,5130,4272,4262,4238,4240,4828,4168,4754,4720,4896,4824,5206,4322,
3800,4826,4632,5104,5134,4838,3858,5008,4828,5234,4324,5282,5348,5150,4724,4682,
4720,5218,4744,4742,4760,5194,4792,4712,4754,4704};
int stack[72],top,aim;
void out()
{
int i;
for (i=0;i<top;i++)
{
printf("%d ",stack[i]);
}
printf("\n");
}
void dfs(int now,int forstart)
{
int i;
if (now==aim)
{
out();
return ;
}
for (i=forstart;i<72;i++)
{
if (now+data[i]<=aim)
{
stack[top++]=data[i];
dfs(now+data[i],i+1);
top--;
}
}
return ;
}
int main()
{
while (scanf("%d",&aim))
{
top=0;
dfs(0,0);
}
return 0;
}
----------------解决方案--------------------------------------------------------
楼上太有才了
----------------解决方案--------------------------------------------------------
这道题还有一种解法,穷举发...貌似二进制算法
----------------解决方案--------------------------------------------------------
#include<iostream.h>
#include"stdio.h"
#define LEN 10
#define NUM 30
int loc=LEN-1;
int a[LEN]={10,20,15,30,28,29,2,15,12,1};
char s[LEN]={'0','0','0','0','0','0','0','0','0','0'};
void Deal_S()
{
int sum=0;
for(int i=0;i<LEN;i++)
{
if(s[i]=='1')
sum+=a[i];
}
if(s[loc]=='1') {loc--;}
if(sum==NUM) ; /*结果处理 */
}
void Increase_S()
{
int i;
for(i=0;i<LEN;i++)
{
if(s[i]=='0'){s[i]='1';break;}
s[i]='0';
}
Deal_S();
}
int main()
{
while(loc>0)
Increase_S();
return 0;
}
----------------解决方案--------------------------------------------------------
11楼的哥们说说你的程序怎么用啊?要输入的是什么?
----------------解决方案--------------------------------------------------------
要输入的是像题目里面的目标数,就是几个数加起来等于的这个数...
----------------解决方案--------------------------------------------------------
要输入的是像题目里面的目标数,就是几个数加起来等于的这个数...
----------------解决方案--------------------------------------------------------
要输入的是像题目里面的目标数,就是几个数加起来等于的这个数...
那建议运行完如果没找到有个提示,就不用再等了啊
----------------解决方案--------------------------------------------------------
这里写得还都只是实现的算法;
不用具体到那么细;
----------------解决方案--------------------------------------------------------