POJ 1844
#include <iostream> #define MAXN 20 using namespace std; int value[MAXN]; int place[MAXN]; int dp[MAXN][15000]; int main() { //freopen("acm.acm","r",stdin); int n; int c; int i; // cin>>n; // cin>>c; scanf("%d",&n); scanf("%d",&c); for(i = 0; i < n; ++ i) { //cin>>place[i]; scanf("%d",&place[i]); } for(i = 0; i < c; ++ i) { //cin>>value[i]; scanf("%d",&value[i]); } memset(dp,0,sizeof(dp)); for(i = 0; i < n; ++ i) { ++ dp[0][7500 + value[0]*place[i] ]; } int k; int tem; int j; for(i = 1; i < c; ++ i) { for(j = 0; j < n; ++ j) { for(k = 15000; k >= 0; -- k) { tem = k - (place[j]*value[i]); if(tem >= 0) { dp[i][k] += dp[i-1][tem]; } } } } //cout<<dp[c-1][7500]<<endl; printf("%d\n",dp[c-1][7500]); }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com