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 forget to take $25000000 from Bush!
“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!
Input
Input contains multiple test cases. Each test case contains 3 positive integers num_1, num_2 and num_5 (0<=num_i<=1000). A test case containing 0 0 0 terminates the input and this test case is not to be processed.
Output
Output the minimum positive value that one cannot pay with given coins, one line for one case.
Sample Input
1 1 30 0 0
Sample Output
4
Author
lcy
Recommend
https://blog.csdn.net/dsaghjkye/article/details/79965837和这个题也差不多
题意:你有 a个1元,b个2元,c个5元 ,问你最小的不能正好支付的钱是多少
解:c1[i]=j代表的是组成i的方案有j种,c2的意义和c1相同,不过c2是再引入1个新的元素后,方案的变化,然后我们把c2的值赋给c1,c2重新归零
显然 我们第 1个元素是 1,他有 a个,那么 for(i,0,a) c2[i] =1
第二个元素是 2 ,有 b 个 for(i,0,a) for(j , 0, b)
0 : c2[0]+=c1[0] c2[0+(2*j)]+=c1[0] .......
1 : c2[1]+=c1[1] c2[ 1+(2*j)] +=c1[0] ........
.......
a :.......................
然后我们把c2的值赋给c1,清空c2
第 三个元素 是 5 ,有 c个 for(i, 0,a+ 2*b) for( j ,0 , c)
0: c2[0+(5*j)]+=c1[0] ......
..........
a+ 2*b : ..........
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<math.h>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
int c1[11330],c2[11330];
int num[5];
int a[12]={0,1,2,5};
int main()
{
int n;
while(~scanf("%d%d%d",&num[1],&num[2],&num[3])&&num[1]+num[2]+num[3])
{
memset(c2,0,sizeof(c2));
memset(c1,0,sizeof(c1));
for(int i=0;i<=num[1];i++)//1号元素
c1[i]=1;
int ans=num[1];
for(int i=2;i<=3;i++)//一共 3个元素
{
for(int j=0;j<=ans;j++) //到上一个元素能取得的最大值
{
for(int k=0;k<=num[i];k++) //当前元素的个数
{
c2[j+k*a[i]]+=c1[j];
}
}
ans+=num[i]*a[i]; //最大值改变
for(int j=0;j<=ans;j++) //c2赋给c1
c1[j]=c2[j];
memset(c2,0,sizeof(c2)); //c2 清空
}
int i;
for(i=0;i<11300;i++)
{
if(c1[i]==0)
{
printf("%d\n",i);
break;
}
}
}
}
https://blog.csdn.net/dsaghjkye/article/details/79991792
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<math.h>
#include<queue>
#include<map>
#include<vector>
#include<set>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
int v[3511330];
int w[11];
int a[10]={0,1,2,5};
int main()
{
int yy=1;
while(~scanf("%d%d%d",&w[1],&w[2],&w[3])&&w[1]+w[2]+w[3])
{
int sum=0;
for(int i=1;i<=3;i++)
sum+=w[i]*a[i];
memset(v,0,sizeof(v));
v[0]=1;
for(int i=1;i<=3;i++)
{
for(int j=1;w[i];j=j<<1)
{
int u=a[i]*(j<=w[i]?j:w[i]);
for(int k=sum;k>=u;k--)
{
if(v[k-u]) v[k]=1;
}
if(j>w[i]) break;
w[i]-=j;
}
}
for(int i=1;i<=sum+1;i++)
{
if(v[i]==0)
{
printf("%d\n",i);
break;
}
}
}
}