标签:
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4258 Accepted Submission(s): 1197
1 #include<stdio.h> 2 #include<string.h> 3 #define mem(a) memset(a,0,sizeof(a)) 4 const int MAXN=10010; 5 int main(){ 6 int n,p[MAXN],m[MAXN],a[MAXN],b[MAXN]; 7 while(~scanf("%d",&n),n){ 8 int sum=0; 9 mem(a);mem(b); 10 for(int i=1;i<=n;i++) 11 scanf("%d%d",&p[i],&m[i]),sum+=m[i]*p[i]; 12 for(int i=0;i<=m[1];i++) 13 a[p[1]*i]=1,b[i]=0;//p[1] 14 if(sum%3!=0)puts("sorry"); 15 else{ 16 sum/=3; 17 for(int i=2;i<=n;i++){ 18 for(int j=0;j<=sum;j++) 19 for(int k=0,t=0;k<=sum&&t<=m[i];k+=p[i],t++) 20 b[j+k]+=a[j]; 21 for(int j=0;j<=sum;j++) 22 a[j]=b[j]%10000,b[j]=0; 23 } 24 // for(int i=0;i<=sum;i++)printf("%d ",a[i]); 25 // puts(""); 26 if(a[sum]==0)puts("sorry"); 27 else printf("%d\n",a[sum]); 28 } 29 } 30 return 0; 31 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4823764.html