POJ 1837
1 #include <iostream> 2 #define MAXN 20 3 using namespace std; 4 5 int value[MAXN]; 6 int place[MAXN]; 7 int dp[MAXN][15000]; 8 9 int main() 10 { 11 //freopen("acm.acm","r",stdin); 12 int n; 13 int c; 14 int i; 15 // cin>>n; 16 // cin>>c; 17 scanf("%d",&n); 18 scanf("%d",&c); 19 for(i = 0; i < n; ++ i) 20 { 21 //cin>>place[i]; 22 scanf("%d",&place[i]); 23 } 24 for(i = 0; i < c; ++ i) 25 { 26 //cin>>value[i]; 27 scanf("%d",&value[i]); 28 } 29 memset(dp,0,sizeof(dp)); 30 for(i = 0; i < n; ++ i) 31 { 32 ++ dp[0][7500 + value[0]*place[i] ]; 33 } 34 35 int k; 36 int tem; 37 int j; 38 39 for(i = 1; i < c; ++ i) 40 { 41 for(j = 0; j < n; ++ j) 42 { 43 for(k = 15000; k >= 0; -- k) 44 { 45 tem = k - (place[j]*value[i]); 46 if(tem >= 0) 47 { 48 dp[i][k] += dp[i-1][tem]; 49 } 50 } 51 } 52 } 53 //cout<<dp[c-1][7500]<<endl; 54 printf("%d\n",dp[c-1][7500]); 55 }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com