hdu2110Crisis of HDU
0<pi,mi<10 这个条件貌似不对,用p[i] m[i]分别储存才过(之前是模板的方法)
#include<iostream> using namespace std; int c1[4000],c2[4000],X[101],P[101]; int main() { int T,n,m,k,a,b,i,j,num,sum; while(scanf("%d",&n),n) { memset(X,0,sizeof(X)); for(sum=0,i=1;i<=n;i++) { scanf("%d%d",&P[i],&X[i]); sum+=P[i]*X[i]; } if(sum%3) { printf("sorry\n"); continue; } sum/=3; memset(c1,0,sizeof(c1));memset(c2,0,sizeof(c2)); for(i=1;i<=n;i++) if(X[i]) { for(num=0;num<=X[i];num++) if(num*P[i]<=sum) c1[num*P[i]]=1; else break; break; } for(i=i+1;i<=n;i++) { if(X[i]) { for(j=0;j<=sum;j++) if(c1[j]) for(num=0;num<=X[i];num++) if(num*P[i]+j<=sum) c2[num*P[i]+j]+=c1[j]; else break; for(j=1;j<=sum;j++) { c1[j]=c2[j]%10000; c2[j]=0; } } } if(c1[sum]==0) printf("sorry\n"); else printf("%d\n",c1[sum]%10000); } return 0; }