uva 10313 Pay the Price(完全背包)
2013-09-13 14:01
363 查看
题目连接:10313 - Pay the Price
题目大意:有0~300这300种价值的金额。
现在可能给出参数:
1个:n, 输出可以组成价值n的方式的个数。
2个:n, a输出用个数小于a的价值组成价值n的方式的个数。
3个:n, a, b输出用个数大于a和小于b组成价值n的方式的个数。
解题思路:完全背包的问题, 状态转移方程dp[i][j] 表示价值i用j个硬币组成的方式种类, 转移方程dp[j][k] += dp[j - i][k - 1]。
题目大意:有0~300这300种价值的金额。
现在可能给出参数:
1个:n, 输出可以组成价值n的方式的个数。
2个:n, a输出用个数小于a的价值组成价值n的方式的个数。
3个:n, a, b输出用个数大于a和小于b组成价值n的方式的个数。
解题思路:完全背包的问题, 状态转移方程dp[i][j] 表示价值i用j个硬币组成的方式种类, 转移方程dp[j][k] += dp[j - i][k - 1]。
#include <stdio.h> #include <string.h> #include <stdlib.h> const int N = 305; long long dp ; void Init() { memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (int i = 1; i <= 300; i++) { for (int j = i; j <= 300; j++) { for (int k = 1; k <= 300; k++) dp[j][k] += dp[j - i][k - 1]; } } } int main() { Init(); int n, a, b; char str ; while (gets(str)) { int flag = sscanf(str, "%d%d%d", &n, &a, &b); long long sum = 0; if (a > 300) a = 300; if (b > 300) b = 300; if (flag == 1) { for (int i = 0; i <= n; i++) sum += dp [i]; } else if (flag == 2) { for (int i = 0; i <= a; i++) sum += dp [i]; } else if (flag == 3) { for (int i = a; i <= b; i++) sum += dp [i]; } printf("%lld\n", sum); } return 0; }
相关文章推荐
- UVA - 10313Pay the Price(完全背包)
- uva 10313 Pay the Price(完全背包)
- UVA - 10313 Pay the Price 整数的划分问题 01背包
- UVa 10313 - Pay the Price
- UVA 10313 Pay the Price(数字分解DP)
- UVa 10313 Pay the Price(类似数字分解DP)
- dp(整数拆分 uva10313 - Pay the Price)
- uva 10313 - Pay the Price
- 解题报告(一):uva 10313 - Pay the Price (dp)
- UVA 10313 Pay the Price
- UVA 10313 Pay the Price
- uva 10313 Pay the Price (DP)
- uva 10313 - Pay the Price
- uva 10313 Pay the Price
- UVA 10313 Pay the Price
- UVA 10313-Pay the Price(DP)
- UVA - 10313 Pay the Price
- UVa 10313 Pay the Price (DP&整数拆分)
- UVA10313- Pay the Price
- uva 10313 Pay the Price