Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13505 Accepted Submission(s): 6094
Problem Description
We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China!
“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 fZ喎?http://www.Bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcmdldCB0byB0YWtlICQyNTAwMDAwMCBmcm9tIEJ1c2ghPGJyPgoKIAo8cD48YnI+CiA8L3A+CklucHV0CjxwPiA8L3A+CklucHV0IGNvbnRhaW5zIG11bHRpcGxlIHRlc3QgY2FzZXMuIEVhY2ggdGVzdCBjYXNlIGNvbnRhaW5zIDMgcG9zaXRpdmUgaW50ZWdlcnMgbnVtXzEsIG51bV8yIGFuZCBudW1fNSAoMDw9bnVtX2k8PTEwMDApLiBBIHRlc3QgY2FzZSBjb250YWluaW5nIDAgMCAwIHRlcm1pbmF0ZXMgdGhlIGlucHV0IGFuZCB0aGlzIHRlc3QgY2FzZSBpcyBub3QgdG8gYmUgcHJvY2Vzc2VkLjxicj4KCiAKPHA+PGJyPgogPC9wPgpPdXRwdXQKPHA+IDwvcD4KT3V0cHV0IHRoZSBtaW5pbXVtIHBvc2l0aXZlIHZhbHVlIHRoYXQgb25lIGNhbm5vdCBwYXkgd2l0aCBnaXZlbiBjb2lucywgb25lIGxpbmUgZm9yIG9uZSBjYXNlLjxicj4KCiAKPHA+PGJyPgogPC9wPgpTYW1wbGUgSW5wdXQKPHA+IDwvcD4KCjxwcmUgY2xhc3M9"brush:java;">1 1 3
0 0 0
Sample Output
4
Author
lcy
解題思路:
本題的母函數為 (1+x +x^2+x^3+.........x^num1) *( 1+x^2+x^4+x^6+.........x^num2) *( 1+x^5+x^10+x^15+............x^num5)
其中num1代表一分的硬幣有多少個,num2代表2分的硬幣多少個,num5代表5分的硬幣有多少個。
模擬三個式子相乘,先前兩個,合並後和第三個相乘。一定要注意指數的變化范圍。給定了num1 num2 num5後,每一個式子的最大指數和計算後的總式子的最大指數都是確定的。
代碼:
#include
using namespace std;
int num1,num2,num5;
int c[9000],temp[9000];//注意范圍,計算方法為 1000*1+1000*2+1000*5 ,8000為最大指數。
int main()
{
while(cin>>num1>>num2>>num5&&num1||num2||num5)
{
int i,j;
int max=num1*1+num2*2+num5*5;//最大的指數
for(i=0;i<=max;i++)
{
c[i]=0;
temp[i]=0;
}
for(i=0;i<=num1;i++)//先模擬前兩個式子相乘
c[i]=1;
for(i=0;i<=num1;i++)
for(j=0;j<=2*num2;j+=2)//因為沒有給定要求的最大指數,所以不用 j+i<= 多少
{
temp[j+i]+=c[i];
}
for(i=0;i<=num1+2*num2;i++)
{
c[i]=temp[i];
temp[i]=0;
}
for( i=0;i<=num1+2*num2;i++)//模擬前兩個式子合並後的式子與第三個式子相乘,num1+2*num2是前兩個式子相乘後的最大指數
for( j=0;j<=5*num5;j+=5)
temp[j+i]+=c[i];
for(i=0;i<=max;i++)
c[i]=temp[i];
for(i=0;i<=max;i++)
{
if(c[i]==0)//系數為0說明,該指數不存在
{
cout<max)//最大指數都存在,要求最小不存在的只能是max+1
cout<