题意好难懂啊
/** * Problem:POJ1837 * Author:Shun Yao * Time:2013.4.29 * Result:Accepted * Memo:DP */ #include<iostream> #include<cstring> #include<cstdlib> #include<cassert> #include<cstdio> #include<cmath> #include<ctime> #include<algorithm> using namespace std; long n, g, c[22], w[22], f[22][15005]; int main() { static long i, j, k; freopen("poj1837.in", "r", stdin); freopen("poj1837.out", "w", stdout); scanf("%ld%ld", &n, &g); for (i = 1; i <= n; ++i) scanf("%ld", c + i); for (i = 1; i <= g; ++i) scanf("%ld", w + i); memset(f, 0, sizeof f); f[0][7500] = 1; for (i = 1; i<= g; ++i) for (j = 0; j <= 15000; ++j) if (f[i - 1][j]) for (k = 1; k <= n; ++k) f[i][j + c[k] * w[i]] += f[i - 1][j]; printf("%ld", f[g][7500]); fclose(stdin); fclose(stdout); return 0; }