Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 849 Accepted Submission(s): 412
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<cstdlib> #include<algorithm> using namespace std; const int MOD=1e9+7; int n,a[5010],dp[5010]; int main() { int tt; scanf("%d",&tt); while(tt--) { int sum=0; memset(dp,0,sizeof(dp)); dp[0]=1; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); sum+=a[i]; } sum=sum/2; for(int i=1;i<=n;i++) { for(int j=sum;j>=0;j--) { for(int k=1;k<=a[i];k++) { if(j>=k) { dp[j]=(dp[j]+dp[j-k])%MOD; } } } } printf("%d\n",dp[sum]); } return 0; }
原文:http://www.cnblogs.com/a972290869/p/4249355.html