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 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 3

0 0 0

Sample Output

4

母函数,注意的是每一个式子不是无限的,所以要加上一个cot<=b和cot<=c表示一个式子只有b,c项,不要超过了
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int c1[],c2[];
int main()
{
int a,b,c;
int num;
while(cin>>a>>b>>c)
{
memset(c1,,sizeof(c1));
memset(c2,,sizeof(c2));
if(a==&&b==&&c==) break;
for(int i=;i<=a;i++)
{
c1[i]=;
}
num = a+*b+*c;
int k,cot;
for(int j=;j<=num;j++)
{
for(k=,cot=;k+j<=num&&cot<=b;k+=,cot++)
{
c2[j+k]+=c1[j];
}
}
for(int j=; j<=num; j++)
{
c1[j] = c2[j];
c2[j] =;
}
for(int j=; j<=num; j++)
{
for(k=,cot=; k+j<=num&&cot<=c; k+=,cot++)
{
c2[j+k]+=c1[j];
}
}
for(int j=; j<=num; j++)
{
c1[j] = c2[j];
c2[j] =;
}
int i;
for(i=;;i++)
{
if(!c1[i])
{
break;
}
}
cout<<i<<endl;
}
return ;
}

最新文章

  1. 深入理解Spark RDD
  2. canvas/CSS实现仪表盘效果
  3. JS 获取当前浏览器类型
  4. aspose.Cells 导出Excel
  5. CSS3秘笈:第二章
  6. datetime处理日期和时间
  7. R语言通过loess去除某个变量对数据的影响--CNV分析
  8. ip网关配置
  9. ndoe.js 和npm私有仓库的搭建
  10. Apache Ignite 学习笔记(二): Ignite Java Thin Client
  11. 如何用SPY++工具查看窗体的句柄
  12. 【 腾讯敏捷转型No.4 】为什么敏捷团队不要超过15人
  13. Android开发之动态检索(Filter)联系人
  14. 《Effective Java》读书笔记七(通用程序设计)
  15. GitBook入门(用github做出第一本书)——超详细配图说明
  16. Tomcat服务时区设置
  17. centos7 yum安装遇到报错:Head V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEYer
  18. 网络安全之iptables防火墙
  19. BestCoder Round #65 (ZYB&#39;s Premutation)
  20. Java 连接池的工作原理(转)

热门文章

  1. hadoop job -kill 与 yarn application -kii(作业卡了或作业重复提交或MapReduce任务运行到running job卡住)
  2. 使用myeclipse开发Servlet
  3. activity的四种加载模式介绍
  4. ROS与Matlab系列:一个简单的运动控制
  5. iOS 通过接受距离传感器的消息改变屏幕的明暗度(仅限用于真实的手机)
  6. redis 有用
  7. 旋转矩阵(Rotate Matrix)的性质分析
  8. Java-马士兵设计模式学习笔记-工厂模式-简单工厂
  9. GCD 学习(三)Main&amp;Global Dispatch Queue
  10. loj10087 Intervals