POJ 1285 - Combinations, Once Again 泛化背包!
来源:互联网 发布:淘宝秒杀不能付款 编辑:程序博客网 时间:2024/05/22 14:02
题目地址:http://poj.org/problem?id=1285
其实就是很简单的一道背包题目。 并且泛化背包并没有什么难点。
这道题只需要枚举每个数的个数就好了, dp[i[背包容量为i的答案, 状态转移方程:dp[i] += dp[i - x] (x为枚举某个数的个数)
#include <cstdio>#include <algorithm>#include <string>#include <cmath>#include <set>#include <map>#include <vector>#include <cstdlib>#include <queue>#include <iostream>#include <functional>#include <cstring>#define UFOR(i, a, b) for(int i = a; i <= b; i++)#define DFOR(i, a, b) for(int i = a; i >= b; i--)#define MEM0(a) memset(a, 0, sizeof(a))#define MEM1(a) memset(a, -1, sizeof(a))#define MEMINF(a) memset(a, 0x3f3f3f3f, sizeof(a))#define lson l, m, rt << 1#define rson m + 1, r, rt << 1 | 1#define FIN freopen("in.txt", "r", stdin)#define FOUT freopen("out.txt", "w", stdout)using namespace std;//typedef __int64 LL;typedef long long LL;const int MXN = 2e3 + 10;const int MXM = 2e4 + 130;const int HS = 1000007;const int INF = 0x3f3f3f3f;const int MOD = 1000000007;int num[55];LL dp[55];int main (){ int n, m, kase = 1; while (~scanf("%d %d", &n, &m), n > 0) { MEM0(num); MEM0(dp); UFOR (i, 1, n) { int k; scanf("%d", &k); num[k]++; } dp[0] = 1; UFOR (i, 1, n) { if (num[i] == 0) continue; DFOR (j, n, 0) { UFOR (x, 1, num[i]) { //注意x不能为0 , 因为j是倒着循环的。 if (j - x >= 0) dp[j] += dp[j - x]; } } } printf("Case %d:\n", kase++); while (m--) { int x; scanf("%d", &x); printf("%I64d\n", dp[x]); } } return 0;}
0 0
- POJ 1285 - Combinations, Once Again 泛化背包
- POJ 1285 - Combinations, Once Again 泛化背包!
- poj-1285 Combinations, Once Again(DP)
- POJ 1285 Combinations, Once Again 笔记
- 1285:Combinations, Once Again
- poj 1155 TELE(树形泛化背包dp)
- poj 1155 TELE 树形dp泛化背包
- POJ 1947 - Rebuilding Roads 树型DP(泛化背包转移)..
- POJ 1155 - TELE 树形DP(泛化背包转移)..
- 2 walks Once again
- 背包again
- hdu3593泛化背包
- 背包问题-泛化物品
- 泛化背包问题
- BNUOJ--19139 PvZ once again
- Codeforces 582B Once Again...
- 泛化物品的背包问题
- HDU1561 树形dp,泛化背包
- HDU 3642 Get The Treasury (线段树扫描线进阶--求长方体重叠3次或以上的体积)
- [搜索]hdu5336
- linux之wait函数
- 关于android:configChanges
- 088 Merge Sorted Array [Leetcode]
- POJ 1285 - Combinations, Once Again 泛化背包!
- BRISK: Binary Robust Invariant Scalable Keypoints
- Swift-分支
- postgresql 导数据时无需输入密码设置
- Swift-循环
- android 的屏幕适配
- 手机脱离电脑持续抓LOG教程
- Single Number II LeetCode
- 数据结构学习笔记5-寻找最小的k个数(选择排序和堆排序)