题目http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=615
分析:计算背包方案数目
#include<cstdio>
#include<cstring>
using namespace std;
int a[5]={1,5,10,25,50},dp[7500];
int amount;
int main()
{
while (scanf("%d",&amount)!=EOF)
{
memset(dp,0,sizeof(dp));
dp[0]=1;
for(int i=0;i<5;i++)
for(int j=a[i];j<=amount;j++)
dp[j]=dp[j]+dp[j-a[i]];
printf("%d ",dp[amount]);
}
return 0;
}
#include<cstring>
using namespace std;
int a[5]={1,5,10,25,50},dp[7500];
int amount;
int main()
{
while (scanf("%d",&amount)!=EOF)
{
memset(dp,0,sizeof(dp));
dp[0]=1;
for(int i=0;i<5;i++)
for(int j=a[i];j<=amount;j++)
dp[j]=dp[j]+dp[j-a[i]];
printf("%d ",dp[amount]);
}
return 0;
}