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;
}
代码如下:
#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;
}
相关文章推荐
- UVA - 357 Let Me Count The Ways
- UVA - 357 Let Me Count The Ways
- UVa 357 - Let Me Count The Ways
- uva 357 - Let Me Count The Ways
- UVa 357 - Let Me Count The Ways
- UVA 357 - Let Me Count The Ways
- UVA 357 Let me count the ways
- uva357 Let Me Count The Ways
- UVA 357 Let Me Count The Ways 动态规划解法、母函数解法
- UVa 357 Let Me Count The Ways
- UVA 357 Let Me Count The Ways (dp + 完全背包)
- UVA-357-Let Me Count The Ways
- uva 357 Let Me Count The Ways
- uva 357 - Let Me Count The Ways(动态规划-注意dp初始化的问题)
- UVA 357 Let Me Count The Ways
- UVA 357 - Let Me Count The Ways
- uva357 - Let Me Count The Ways(动规,母函数)
- UVa 357 - Let Me Count The Ways
- UVa 357: Let Me Count The Ways
- uva 357 - Let Me Count The Ways