标签:amp main output arm man size int form bitset
Input
Output
Sample Input
2 4 -2 3 3 4 5 8
Sample Output
2
递推,注意到砝码一边的最大重量不超过7500,讲7500设为新的0点,枚举所有物品选择和节点选择,注意剪枝。。
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<sstream> #include<algorithm> #include<queue> #include<vector> #include<cmath> #include<map> #include<stack> #include<set> #include<memory> #include<bitset> #include<string> #include<functional> using namespace std; typedef long long LL; typedef unsigned long long ULL; const int MAXN = 8000 * 2; #define INF 0x3f3f3f3f //0 1 背包 /* dp[i][MAXN] */ int dp[25][MAXN]; int x[25], w[25]; int solve(int c, int g) { for (int i = 1; i <= g; i++) { for (int v = 0; v < MAXN; v++) { if (dp[i - 1][v]) { for (int j = 1; j <= c; j++) { dp[i][v + w[i] * x[j]] += dp[i - 1][v]; } } } } return dp[g][7500]; } int main() { int c, g; scanf("%d%d", &c, &g); memset(dp, 0, sizeof(dp)); for (int i = 1; i <= c; i++) scanf("%d", &x[i]); for (int j = 1; j <= g; j++) scanf("%d", &w[j]); /*for (int i = 0; i < c; i++) { for (int j = 0; j < g; j++) { dp[0][x[i] * w[j] + 7500]++; } }*/ dp[0][7500] = 1; printf("%d\n", solve(c, g)); return 0; }
标签:amp main output arm man size int form bitset
原文地址:http://www.cnblogs.com/joeylee97/p/7403763.html