The trouble of Xiaoqian

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2166    Accepted Submission(s): 773

Problem Description
In
the country of ALPC , Xiaoqian is a very famous mathematician. She is
immersed in calculate, and she want to use the minimum number of coins
in every shopping. (The numbers of the shopping include the coins she
gave the store and the store backed to her.)
And now , Xiaoqian wants
to buy T (1 ≤ T ≤ 10,000) cents of supplies. The currency system has N
(1 ≤ N ≤ 100) different coins, with values V1, V2, ..., VN (1 ≤ Vi ≤
120). Xiaoqian is carrying C1 coins of value V1, C2 coins of value V2,
...., and CN coins of value VN (0 ≤ Ci ≤ 10,000). The shopkeeper has an
unlimited supply of all the coins, and always makes change in the most
efficient manner .But Xiaoqian is a low-pitched girl , she wouldn’t like
giving out more than 20000 once.
 
Input
There are several test cases in the input.
Line 1: Two space-separated integers: N and T.
Line 2: N space-separated integers, respectively V1, V2, ..., VN coins (V1, ...VN)
Line 3: N space-separated integers, respectively C1, C2, ..., CN
The end of the input is a double 0.
 
Output
Output
one line for each test case like this ”Case X: Y” : X presents the Xth
test case and Y presents the minimum number of coins . If it is
impossible to pay and receive exact change, output -1.
 
Sample Input
3 70
5 25 50
5 2 1
0 0
 
Sample Output
Case 1: 3
此题为多重背包和完全背包的混合,可分开求,在求最小值
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll dpf[],dps[];
ll a[],b;
ll ans,pos,n,m;
int main()
{
int count=;
while(scanf("%lld%lld",&n,&m) && n+m)
{
for(int i=;i<;i++)
{
dps[i]=dpf[i]=INF;
}
dps[]=dpf[]=;
for(int i=;i<n;i++)
{
scanf("%lld",&a[i]);
}
for(int i=;i<n;i++)
{
scanf("%lld",&b);
for(int k=;b;k*=)
{
if(b<k) k=b;
for(int j=;j>=k*a[i];j--)
{
dpf[j]=min(dpf[j],dpf[j-k*a[i]]+k);
}
b-=k;
}
}
for(int i=;i<n;i++)
{
for(int j=a[i];j<=;j++)
{
dps[j]=min(dps[j],dps[j-a[i]]+);
}
}
ans=INF;
for(int i=m;i<=;i++)
{
ans=min(ans,dpf[i]+dps[i-m]);
}
if(ans==INF) ans=-;
printf("Case %d: %lld\n",count++,ans);
}
return ;
}

HDU 3594 The trouble of Xiaoqian 混合背包问题的更多相关文章

  1. HDU 3591 The trouble of Xiaoqian(多重背包+全然背包)

    HDU 3591 The trouble of Xiaoqian(多重背包+全然背包) pid=3591">http://acm.hdu.edu.cn/showproblem.php? ...

  2. hdu 3591 The trouble of Xiaoqian

    hdu 3591  The trouble of Xiaoqian 题意:xiaoqi要买一个T元的东西,当前的货币有N种,xiaoqi对于每种货币有Ci个:题中定义了最小数量即xiaoqi拿去买东西 ...

  3. HDU - 3591 The trouble of Xiaoqian 题解

    题目大意 有 \(N\) 种不同面值的硬币,分别给出每种硬币的面值 \(v_i\) 和数量 \(c_i\).同时,售货员每种硬币数量都是无限的,用来找零. 要买价格为 \(T\) 的商品,求在交易中最 ...

  4. The trouble of Xiaoqian

    The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...

  5. HDUOJ-----3591The trouble of Xiaoqian

    The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  6. HDU 3594.Cactus 仙人掌图

    Cactus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  7. HDU 2602 Bone Collector(经典01背包问题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...

  8. HDU 3594 Cactus(仙人掌问题)

    http://acm.hdu.edu.cn/showproblem.php?pid=3594 题意: 一个有向图,判断是否强连通和每条边只在一个环中. 思路: 仙人掌问题. 用Tarjan算法判断强连 ...

  9. hdu - 3594 Cactus (强连通)

    http://acm.hdu.edu.cn/showproblem.php?pid=3594 判断给定的图是否是强连通的,并且每条边都只属于一个连通分量. 判断强连通只需要判断缩点之后顶点数是否为1即 ...

随机推荐

  1. 把枚举类型绑定到datasource

    /// <summary> ///ProjectPriority 的摘要说明 /// </summary> public enum ProjectPriority { 极低 = ...

  2. EasyUI--Alert()

    1.$.messager.alert(title, msg, icon, fn) 2 <script type="text/javascript"> $(functio ...

  3. JDOJ 2939: Suffix Automaton 广义后缀自动机_统计子串

    建立广义后缀自动机,对每个节点都建立各自的 $Parent$ 数组. 这样方便统计,不会出现统计错误. 考虑新加入一个字符. 1 这条转移边已经存在,显然对答案没有贡献. 2 这条转移边不存在,贡献即 ...

  4. man帮助

    man命令是Linux下的帮助指令,通过man指令可以查看Linux中的指令帮助.配置文件帮助和编程帮助等信息.

  5. lsof---查看你进程开打的文件

    lsof命令用于查看你进程开打的文件,打开文件的进程,进程打开的端口(TCP.UDP).找回/恢复删除的文件.是十分方便的系统监视工具,因为lsof命令需要访问核心内存和各种文件,所以需要root用户 ...

  6. Linux学习总结(9)——Linux 新手必知必会的 10 条 Linux 基本命令

    Linux 对我们的生活产生了巨大的冲击.至少你的安卓手机使用的就是 Linux 核心.尽管如此,在第一次开始使用 Linux 时你还是会感到难以下手.因为在 Linux 中,通常需要使用终端命令来取 ...

  7. 可穿戴KEY带来的身份认证的革命

    在用户身份认证方面,PKI体系给出了极好的解决方式.即基于X.509数字证书的用户身份认证.该方法基于非对称公钥算法的难题为用户提供非常安全的认证过程. PKI体系尽管明白要求"私钥必须保密 ...

  8. Css 选择器总结

    选择器 .class 类对应的元素. #id 对应的id元素. * 全部元素 div{} 对应的标签 div,p{} 全部的div和p div p{} div下全部的p标签 div>p{} di ...

  9. Codeforces 327A-Flipping Game(暴力枚举)

    A. Flipping Game time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  10. PowerShell中和服务相关的命令

    New-Service https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-s ...