Holding Bin-Laden Captive!(母函数)
Holding Bin-Laden Captive!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17732 Accepted Submission(s): 7940
“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<stdio.h>
#include<string.h>
const int MAXN=;
int a[MAXN],b[MAXN];
int main(){
int x,y,z,sum;
int money[],t[];
while(scanf("%d%d%d",&x,&y,&z),x||y||z){
memset(a,,sizeof(a));memset(b,,sizeof(b));//初始化。。。
for(int i=;i<=x;i++)a[i]=,b[i]=;
t[]=x;t[]=y;t[]=z;
money[]=;money[]=;money[]=;
sum=money[]*t[];
for(int i=;i<;i++){
for(int j=;j<=sum;j++)
for(int k=;k<=money[i]*t[i];k+=money[i])
b[j+k]+=a[j];
sum+=money[i]*t[i];
for(int j=;j<=sum;j++)
a[j]=b[j];
}
//printf("%d\n",sum);
for(int i=;i<=sum+;i++)
if(!a[i]){
printf("%d\n",i);
break;
}
}
return ;
}
extern "C++"{
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int INF = 0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long LL;
typedef unsigned long long ULL; void SI(int &x){scanf("%d",&x);}
void SI(double &x){scanf("%lf",&x);}
void SI(LL &x){scanf("%lld",&x);}
void SI(char *x){scanf("%s",x);} }
const int MAXN = ;
int a[MAXN],b[MAXN];
int num[];
int v[];
int main(){
while(~scanf("%d%d%d",&num[],&num[],&num[]),num[]|num[]|num[]){
mem(a,);mem(b,);
v[] = ;v[] = ;v[] = ;
int sum = ;
for(int i = ;i <= num[];i++)a[i] = v[],b[i] = ,sum += v[i] * num[i];
//int sum = num[0] * v[0];
for(int i = ;i <= ;i++){
for(int j = ;j <= sum;j++){
for(int k = ;k <= num[i];k++){
b[j + k * v[i] ] += a[j];
}
}
// sum += num[i] * v[i];
for(int j = ; j <= sum; j++)a[j] = b[j],b[j] = ;
}
int ans;
for(int i = ;i <= sum + ;i++){
if(a[i] == ){
ans = i;
break;
}
}
printf("%d\n",ans);
}
return ;
}
Holding Bin-Laden Captive!(母函数)的更多相关文章
- HDU 1085 Holding Bin-Laden Captive!(母函数,或者找规律)
Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- hdu 1085 Holding Bin-Laden Captive! (母函数)
//给你面值为1,2,5的三种硬币固定的数目,求不能凑出的最小钱数 //G(x)=(1+x+...+x^num1)(1+x^2+...+x^2num2)(1+x^5+,,,+x^5num3), //展 ...
- 【hdoj_1085】Holding Bin-Laden Captive![母函数]
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1085 可以这样理解题意:给出1元,2元和5元的三种硬币若干,每种硬币数量给出,现在可以从所有的硬币中,选出 ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- A过的题目
1.TreeMap和TreeSet类:A - Language of FatMouse ZOJ1109B - For Fans of Statistics URAL 1613 C - Hardwood ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- 缓冲区溢出利用——捕获eip的傻瓜式指南
[译文] 摘要:为一个简单的有漏洞程序写一个简单的缓冲区溢出EXP,聚焦于遇到的问题和关键性的教训,提供详细而彻底的描述 内容表:1. I pity the fool, who can't smash ...
- 用主题模型可视化分析911新闻(Python版)
本文由 伯乐在线 - 东狗 翻译,toolate 校稿.未经许可,禁止转载!英文出处:blog.dominodatalab.com.欢迎加入翻译小组. 本文介绍一个将911袭击及后续影响相关新闻文章的 ...
- How do I learn mathematics for machine learning?
https://www.quora.com/How-do-I-learn-mathematics-for-machine-learning How do I learn mathematics f ...
- Labeled Faces in the Wild 人脸识别数据集 部分测试数据
development test set Note: images displayed are original (non-aligned/funneled) images. match pairs ...
随机推荐
- JQuery DataTables Editor---只修改页面内容
近来在工作中需要对JQuery DataTables进行增,删,改的操作,在网上找了一些资料,感觉比较的好的就是(http://editor.datatables.net/)文章中所展示的操作方法(如 ...
- MFC使用Windows media player播放声音文件
一.在需要播放声音的资源上添加控件 资源视图 . 选择添加控件的资源(如对话框).右键单击.插入ActiveX控件.调整你需要的控件属性并记录ID 二.在项目中添加播放声音的类 点击菜单中的项目.添 ...
- getopt vs getopts
getopt示例 #!/bin/bash aflag=no args=`getopt a: $@` ]; then echo 'Usage: ...' exit fi set -- $args ] d ...
- [amazonaccess 1]logistic.py 特征提取
---恢复内容开始--- 本文件对应logistic.py amazonaccess介绍: 根据入职员工的定位(员工角色代码.角色所属家族代码等特征)判断员工是否有访问某资源的权限 logistic. ...
- 求解printf函数?
求大神解释一下下面的代码为什么答案不是1 2,而是1 0. #include <stdio.h> int ans = 0; int a() { ans = 1; return ans++; ...
- Apache的Access.log分析总结
Apache的Access.log分析总结 #查看80端口的tcp连接 #netstat -tan | grep "ESTABLISHED" | grep ":80&q ...
- 一个利用扩展方法的实例:AttachDataExtensions
扩展方法是C# 3.0(老赵对VB不熟)中最简单,也是最常用的语言特性之一.这是老赵自以为的一个简单却不失经典的实例: [AttributeUsage(AttributeTargets.All, Al ...
- POJ 1703 Find them, Catch them (数据结构-并查集)
Find them, Catch them Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31102 Accepted: ...
- Ubuntu 14.04安装Sogou输入法
在http://pinyin.sogou.com/linux/?r=pinyin页面可下载对应的的deb包.在http://pinyin.sogou.com/linux/help.php页面有搜狗输入 ...
- OC中最难的一部分内容:内存管理
OC中最难的一部分内容:内存管理为什么说他难呢?因为内存如果需要我们程序员去管理的话,那个难度肯定是很大的,如果是Java,垃圾回收器会把这份工作给做了,我们不需要关心,但是就是因为如此,Androi ...