1085


Holding Bin-Laden Captive!

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14095 Accepted Submission(s): 6309

Problem 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


#include <iostream>
#include<stdio.h>
using namespace std;

int c1[10000], c2[10000];
int num[4];
int main()
{
int nNum;
while(scanf("%d %d %d", &num[1], &num[2], &num[3]) && (num[1]||num[2]||num[3]))
{
int _max = num[1]*1+num[2]*2+num[3]*5;
// 初始化
for(int i=0; i<=_max; ++i)
{
c1[i] = 0;
c2[i] = 0;
}
for(int i=0; i<=num[1]; ++i)
c1[i] = 1;
for(int i=0; i<=num[1]; ++i)
for(int j=0; j<=num[2]*2; j+=2)
c2[j+i] += c1[i];
for(int i=0; i<=num[2]*2+num[1]*1; ++i)
{
c1[i] = c2[i];
c2[i] = 0;
}

for(int i=0; i<=num[1]*1+num[2]*2; ++i)
for(int j=0; j<=num[3]*5; j+=5)
c2[j+i] += c1[i];
for(int i=0; i<=num[2]*2+num[1]*1+num[3]*5; ++i) //看到变化了吗
{
c1[i] = c2[i];
c2[i] = 0;
}
int i;

for(i=0; i<=_max; ++i)
if(c1[i] == 0)
{
printf("%d\n", i);
break;
}
if(i == _max+1)
printf("%d\n", i);
}
return 0;
}

1085

时间: 2024-11-05 16:24:14

1085的相关文章

[BZOJ 1085][SCOI2005]骑士精神(IDA*)

题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1085 分析: 首先第一感觉是宽搜,但是空间需要8^15*5*5,明显不够,又鉴于最大深度为15,所以可以用迭代加深做. 但是普通的迭代加深还是会TLE.于是考虑加上估价函数 设当前层数的上界为Kmax,当前搜索的层数为K,我们知道一次移动顶多改变目前矩阵和目标矩阵的一个差别,于是可以求出当前与目标矩阵不同的位置的个数s,如果k+s>Kmax那么就可以直接不做了.

[BZOJ 1085][SCOI 2005]骑士精神(IDA*搜索)

题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1085 考虑到深度不超过15,IDA*搜索可做. 估价函数h()=当前不在目标位置的棋子个数. 然后其他细节就和普通的迭代加深一样了. #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <algorithm>

hdu 1085 Holding Bin-Laden Captive!(母函数)

http://acm.hdu.edu.cn/showproblem.php?pid=1085 题意:1元,2元,5元的硬币分别有num[1],num[2],num[3]个.问用这些硬币不能组合成的最小钱数. 继续母函数. 有两个注意的地方: 对c2[]初始化的同时也要对c1[]初始化. 最后枚举到sum+1,因为存在[1,sum]都可以凑成的可能,这时输出sum+1. #include <stdio.h> #include <iostream> #include <map&g

1085 背包问题(0-1背包模板题)

1085 背包问题(0-1背包模板题)(51NOD基础题) 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 在N件物品取出若干件放在容量为W的背包里,每件物品的体积为W1,W2--Wn(Wi为整数),与之相对应的价值为P1,P2--Pn(Pi为整数).求背包能够容纳的最大价值. Input 第1行,2个整数,N和W中间用空格隔开.N为物品的数量,W为背包的容量.(1 <= N <= 100,1 <= W <= 10000) 第2 - N + 1行,每行

【BZOJ】1085: [SCOI2005]骑士精神

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1085 $${if (cs+val-1>ans) return ;}$$ 1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<vector> 5 #include<cstdlib> 6 #include<cmath> 7 #inc

A*算法详解 BZOJ 1085骑士精神

转载1:A*算法入门 http://www.cppblog.com/mythit/archive/2009/04/19/80492.aspx 在看下面这篇文章之前,先介绍几个理论知识,有助于理解A*算法. 启发式搜索:启发式搜索就是在状态空间中的搜索对每一个搜索的位置进行评估,得到最好的位置,再从这个位置进行搜索直到目标.这样可以省略大量无畏的搜索路径,提到了效率.在启发式搜索中,对位置的估价是十分重要的.采用了不同的估价可以有不同的效果. 估价函数:从当前节点移动到目标节点的预估费用:这个估计

LightOJ 1085 - All Possible Increasing Subsequences (离散化+树状数组+dp)

1085 - All Possible Increasing Subsequences   PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 64 MB An increasing subsequence from a sequence A1, A2 ... An is defined by Ai1, Ai2 ... Aik, where the following properties hold i1 <

HDU 1085

想来想去都有bug 最后简单粗暴的一个一个来处理了 #include<stdio.h> #include<string.h> #include<math.h> #include<iostream> #include<algorithm> #include<queue> #include<stack> #define mem(a,b) memset(a,b,sizeof(a)) #define ll __int64 #def

1085. Perfect Sequence (25)【二分查找】——PAT (Advanced Level) Practise

题目信息 1085. Perfect Sequence (25) 时间限制300 ms 内存限制65536 kB 代码长度限制16000 B Given a sequence of positive integers and another positive integer p. The sequence is said to be a "perfect sequence" if M <= m * p where M and m are the maximum and minim

HDU 1085 Holding Bin-Laden Captive!(DP)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1085 解题报告:有1,2,5三种面值的硬币,这三种硬币的数量分别是num_1,num_2,num_5,问你不能凑的钱的最小值是多少. DP,开一个这样的数组dp[i][3],然后dp[i][0]表示凑成 i 元钱需要dp[i][0]张1块的,需要dp[i][1]张两块的,dp[i][2]张5块的,然后依次往后递推,得到 i 的途径一共有三种,第一种是i-1加一张一块的,第二种是i-2加上1张两块的,