【HDOJ 1085】数学问题,母函数
Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17327 Accepted Submission(s): 7764
“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!
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int a,b,c;
while( cin >> a >> b >> c,a,b,c)
{
if(a >= 4 || (a >= 2 && b >=1) || (a >= 1 && b >= 2))
{
cout << a + b * 2 + c * 5 + 1 << endl;
continue;
}
if(a == 0)
cout << "1" << endl;
else if(b == 0)
cout << a + 1 << endl;
else if(a == 1 && b == 1)
cout << "4" << endl;
}
return 0;
}
#include <iostream>
#include <memory.h>
#define N 8000
using namespace std;
int num[4];
int c1[N+10],c2[N+10];
int main()
{
int i,j,k;
int value[4]= {0,1,2,5};
while(cin>>num[1]>>num[2]>>num[3])
{
if(num[1]==0&&num[2]==0&&num[3]==0)
return 0;
int n=0;
for(i=1;i<=3;i++)
n+=num[i]*value[i];
memset(c1,0,sizeof(c1));
memset(c2,0,sizeof(c2));
c1[0]=1;
for (i=1; i<=3; i++)
{
for (j=0; j<=n; j++)
for (k=0; k*value[i]+j<=n&&k<=num[i]; k++)
{
c2[j+k*value[i]]+=c1[j];
}
for (j=0; j<=n; j++)
{
c1[j]=c2[j];
c2[j]=0;
}
}
int s;
for(s=1;s<=n;s++)
{
if(c1[s]==0)
break;
}
cout<<s<<endl;
}
return 0;
}
【HDOJ 1085】数学问题,母函数的更多相关文章
- HDOJ 1085 Holding Bin-Laden Captive! (母函数)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- Holding Bin-Laden Captive!(杭电1085)(母函数)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDOJ 1709 The Balance(母函数)
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDOJ 2069 Coin Change(母函数)
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDOJ 2079 选课时间(母函数)
选课时间(题目已修改,注意读题) Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDOJ 2082 找单词 (母函数)
找单词 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- HDOJ 1398 Square Coins 母函数
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDOJ 1085 Holding Bin-Laden Captive!
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- HDOJ/HDU 1085 Holding Bin-Laden Captive!(非母函数求解)
Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for ...
随机推荐
- x86主机搭建家庭智能路由系统 ---- 设计篇
组件简介 Proxmox: 基于Debian的虚拟化系统,支持OpenVZ和KVM. pfSense: 基于FreeBSD的开源路由系统. FreeNAS: 开源NAS系统. shadowsocks: ...
- Think PHP 基础
ThinkPHP 一.什么框架: 一堆代码的集合,里边有变量.函数.类.常量,里边也有许多设计模式MVC.AR数据库.单例等等. 框架可以节省我们50-60%的工作量,我们全部精力都集中在业务层次. ...
- sqlserver的一些小知识点
1.高效分页sql和储存过程 select top 每页条数 * from ( select ROW_NUMBER() over (order by id)as nid ,* from table01 ...
- maven新建的项目,不自动引入依赖包
1.检查repository的目录是不是纯英文. 2.重新下载一次repository. 如果解决了问题,那么原因就是前面在加载repository的时候,因为断网导致了下载的包有误,无法被ecl ...
- 说说如何用js实现一个模板引擎
本文同步更新在: https://github.com/whxaxes/blog/issues/4 ,在 github 看文章显示效果会更好一些. 前言 不知不觉就很长时间没造过什么轮子了,以前一直想 ...
- wemall app商城源码android开发MD5加密工具类
wemall-mobile是基于WeMall的android app商城,只需要在原商城目录下上传接口文件即可完成服务端的配置,客户端可定制修改.本文分享android开发MD5加密工具类主要代码,供 ...
- 1232: [Usaco2008Nov]安慰奶牛cheer
1232: [Usaco2008Nov]安慰奶牛cheer Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 612 Solved: 431[Submi ...
- 当前最上层的视图控制器vc 和 当前最上层的导航控制器nav
在处理 URL Router 跳转的时候,我们经常需要得到 当前最上层的视图控制器 和 当前最上层的导航控制器 来进行视图跳转或者方法调用.- (UIViewController *)currentV ...
- c++ string 对象操作
字符串转换大小写如下: #include "stdafx.h" #include <iostream> #include <string> using na ...
- 详解JDBC连接数据库
一.概念 1. 为了能让程序操作数据库,对数据库中的表进行操作,每一种数据库都会提供一套连接和操作该数据库的驱动,而且每种数据库的驱动都各不相同,例如mysql数据库使用mysql驱动,oracle数 ...