Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15198 Accepted Submission(s): 6804
“Oh, God! How terrible! ”
Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up!
Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
“Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
You, super ACMer, should solve the problem easily, and don’t forget to take $25000000 from Bush!
1 1 3 0 0 0
4
/* HDOJ 1085 母函数 G(x)=(1+x+x^2+…+x^n1)(1+x^2+x^4+…+x^(2*n2))(1+x^5+x^25+…+x^(5*n5)) */ #include<iostream> #include<stdio.h> using namespace std; int c1[10002],c2[10002],a[3]={1,2,5},b[3]; int main() { int n1,n2,n5,i,j,k,num; while(scanf("%d%d%d",&n1,&n2,&n5),n1+n2+n5) { num=n1*1+n2*2+n5*5; b[0]=n1;b[1]=n2;b[2]=n5; memset(c1,0,sizeof(c1)); memset(c2,0,sizeof(c2)); c1[0]=1; for(i=0;i<3;i++)//钱的种类 { for(j=0;j<=num;j++)//第j个变量 { if(c1[j]) { //k表示的是第j个指数,所以k每次增i(因为第i个表达式的增量是i) for(k=0;k+j<=num&&k<=a[i]*b[i];k+=a[i]) c2[k+j]+=c1[j]; } } for(j=0;j<=num;j++) { c1[j]=c2[j]; c2[j]=0; } } for(i=1;i<=10002;i++)//不能到num 有可能都能表示 { if(!c1[i]) { printf("%d\n",i); break; } } } return 0; }