您的位置:首页 > 其它

UVa 357 - Let Me Count The Ways

2013-04-15 19:53 465 查看
完全背包问题。

代码如下:

#include <iostream>
#include <cstdio>
using namespace std;
long long dp[30055];
int coin[5] = {1, 5, 10, 25, 50};
int main()
{
int num;
dp[0] = 1;
for(int i=0; i<5; ++i)
{
for(int j=0; j<30001; ++j)
dp[j + coin[i]] += dp[j];
}
while(scanf("%d", &num) != EOF)
{
if(dp[num] != 1)
printf("There are %lld ways to produce %d cents change.\n", dp[num], num);
else
printf("There is only %lld way to produce %d cents change.\n", dp[num], num);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: