Holding Bin-Laden Captive!(hdu1085)——母函数
来源:互联网 发布:javascript input赋值 编辑:程序博客网 时间:2024/05/16 16:03
“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 30 0 0
4
给出3个数,分别代表价值为1,2,5的数量,找出这些硬币不能组成的最小的数
这也是一个母函数模板的题目,只不过我们最好要更新当先cmax的值,然后最后找最小不能组成的值时要找到sum+1,因为有可能1-sum都能组成
#include <iostream>#include <cstring>#include <cstdio>using namespace std;int s[4],ans[8005],tmp[8005],cmax;int num[4];int mu(){ s[1]=1; s[2]=2; s[3]=5; memset(ans,0,sizeof(ans)); memset(tmp,0,sizeof(tmp)); ans[0]=1; cmax=0; for(int i=1;i<=3;i++) { cmax+=num[i]*s[i];//更新j当前的最大值 for(int j=0;j<=cmax;j++) for(int k=0;k<=num[i]&&k*s[i]+j<=8000;k++) { tmp[j+k*s[i]]+=ans[j]; } memcpy(ans,tmp,sizeof(tmp)); memset(tmp,0,sizeof(tmp)); } return 0;}int main(){ while(cin>>num[1]>>num[2]>>num[3]) { if(num[1]==0&&num[2]==0&&num[3]==0) break; mu(); int sum=num[1]+num[2]*2+num[3]*5; for(int i=1;i<=sum+1;i++) if(ans[i]==0) { cout<<i<<endl; break; } } return 0;}
- Holding Bin-Laden Captive!(hdu1085)——母函数
- HDU1085 Holding Bin-Laden Captive!,母函数
- HDU1085 Holding Bin-Laden Captive! 【母函数】
- 【HDU1085】Holding Bin-Laden Captive! 母函数
- hdu1085——Holding Bin-Laden Captive!
- HDU1085 Holding Bin-Laden Captive!(母函数)
- HDU1085 Holding Bin-Laden Captive!(母函数)
- hdu1085-Holding Bin-Laden Captive!
- hdu1085 Holding Bin-Laden Captive!
- hdu1085 Holding Bin-Laden Captive!
- HDU1085 Holding Bin-Laden Captive!
- HDU1085 Holding Bin-Laden Captive!
- hdu1085(Holding Bin-Laden Captive!)
- hdu1085 Holding Bin-Laden Captive!
- (hdu1085)Holding Bin-Laden Captive!(母函数,打表)
- Holding Bin-Laden Captive!(母函数)
- Holding Bin-Laden Captive!(母函数)
- Holding Bin-Laden Captive!(母函数)
- 文件下载filename乱码问题
- 最长递增子序列
- 登录后经常出现You have new mail in /var/spool/mail/root的提示
- celery学习记录
- C++ fill()和fill_n()函数用法
- Holding Bin-Laden Captive!(hdu1085)——母函数
- Android CardView
- java中泛型创建数组的总结
- HDU 6090 Rikka with Graph(思维)
- 性能测试 PTS 铂金版来袭!阿里云发布T级数据压测的终极秘笈
- C#之字符判断和大小写的转换
- java Serializable 接口
- 5179 beautiful number
- Log4j日志配置详解