杭电 HDU ACM 1085 Holding Bin-Laden Captive!
Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16548 Accepted Submission(s): 7436
“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!
0 0 0
#include<iostream>
const int M=100000;
#include<algorithm>
using namespace std;
int main()
{
int i,j,k,n1,n2,n5,cnt[M],dic[M];//cnt 标记 系数 dic 记录每项指数
while(cin>>n1>>n2>>n5,n1+n2+n5)
{
int Min=n1+2*n2+5*n5; //能够出现的最高次幂
for(int h=0; h<=Min; h++)
{
cnt[h]=1;
dic[h]=0;
}
cnt[Min+1]=0;
// 计算前两大项乘开之后的结果
for(j=0; j<=n1; j++)//循环第一项中各项
for(k=0; k<=2*n2; k+=2)
{
dic[j+k]+=cnt[j];//j+k为相乘过程中出现的系数 cnt为上一大项的结果 和这个乘完之后的叠加
}
for(int p=0; p<=2*n2+n1; p++)
{
cnt[p]=dic[p];cnt//保留当前最终系数结果 即前两大项乘完之后的结果
dic[p]=0;
}
for(j=0; j<=2*n2+n1; j++)
for(k=0; k<=5*n5; k+=5)
{
dic[j+k]+=cnt[j];
}
for(int e=0; e<=Min; e++)
{
cnt[e]=dic[e];
dic[e]=0;
}
for(int q=0;; q++)
{
if(!cnt[q])
{
cout<<q<<endl;
break;
}
}
}
return 0;
}