标签:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 13717 | Accepted: 8616 |
Description
Input
Output
Sample Input
2 4 -2 3 3 4 5 8
Sample Output
2
Source
// // main.cpp // poj1837 // // Created by Candy on 9/22/16. // Copyright © 2016 Candy. All rights reserved. // #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int N=25,sh=7500; int read(){ char c=getchar();int x=0,f=1; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1; c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘; c=getchar();} return x*f; } int c,n; int pos[N],w[N],f[N][(sh<<1)+5]; void dp(){ f[0][sh]=1; for(int i=1;i<=n;i++) for(int j=sh<<1;j>=0;j--) if(f[j]){ for(int k=1;k<=c;k++) f[i][j+pos[k]*w[i]]+=f[i-1][j]; } } int main(int argc, const char * argv[]) { c=read();n=read(); for(int i=1;i<=c;i++) pos[i]=read(); for(int i=1;i<=n;i++) w[i]=read(); dp(); printf("%d",f[n][sh]); return 0; }
标签:
原文地址:http://www.cnblogs.com/candy99/p/5898406.html