标签:des style blog http color os io strong ar
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 10655 | Accepted: 6609 |
Description
Input
Output
Sample Input
2 4 -2 3 3 4 5 8
Sample Output
2
Source
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<stdlib.h> 5 #include<algorithm> 6 using namespace std; 7 const int MAXN=20+5; 8 int w[MAXN],v[MAXN]; 9 int dp[MAXN][15005]; 10 int main() 11 { 12 int n,m; 13 while(scanf("%d %d",&n,&m)!=EOF) 14 { 15 for(int i=1;i<=n;i++) 16 scanf("%d",&w[i]); 17 for(int i=1;i<=m;i++) 18 scanf("%d",&v[i]); 19 20 memset(dp,0,sizeof(dp)); 21 dp[0][7500]=1; 22 for(int i=1;i<=m;i++) 23 { 24 for(int j=0;j<=15000;j++) 25 { 26 if(dp[i-1][j])//如果为0,则代表之前没有得到这个状态,不用再计算了 27 { 28 for(int k=1;k<=n;k++) 29 dp[i][j+w[k]*v[i]]+=dp[i-1][j]; 30 } 31 } 32 } 33 printf("%d\n",dp[m][7500]); 34 } 35 return 0; 36 }
标签:des style blog http color os io strong ar
原文地址:http://www.cnblogs.com/clliff/p/3954681.html