HDU-1114 完全背包+恰好装满问题
Description
But there is a big problem with piggy-banks. It is not possible to determine how much money is inside. So we might break the pig into pieces only to find out that there is not enough money. Clearly, we want to avoid this unpleasant situation. The only possibility is to weigh the piggy-bank and try to guess how many coins are inside. Assume that we are able to determine the weight of the pig exactly and that we know the weights of all coins of a given currency. Then there is some minimum amount of money in the piggy-bank that we can guarantee. Your task is to find out this worst case and determine the minimum amount of cash inside the piggy-bank. We need your help. No more prematurely broken pigs!
Input
Output
Sample Input
Sample Output
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int f[];
int w[],p[];
int max(int x,int y)
{
if (x>y) return y;
return x;
}
int main()
{
int t;
scanf("%d",&t);
while (t--)
{
int em,fu;
scanf("%d %d",&em,&fu);
int wei=fu-em;
int n;
scanf("%d",&n);
int i,j,k;
for (i=;i<n;i++)
{
scanf("%d %d",&p[i],&w[i]);
}
for (i=;i<=wei;i++) f[i]=1e9;
f[]=;
for (i=;i<n;i++)
{
for (j=;j<=wei;j++) //从小到大遍历背包容量,完全背包
{
if (j-w[i]>=)
{
f[j]=min(f[j],f[j-w[i]]+p[i]);
}
}
}
if (f[wei]==1e9) puts("This is impossible.");//若满足条件,说明根本不能恰好装满。
else
printf("The minimum amount of money in the piggy-bank is %d.\n",f[wei]);
}
return ;
}
HDU-1114 完全背包+恰好装满问题的更多相关文章
- 题解报告:hdu 1114 Piggy-Bank(完全背包恰好装满)
Problem Description Before ACM can do anything, a budget must be prepared and the necessary financia ...
- HDU - 1114 Piggy-Bank 完全背包(背包恰好装满)
Piggy-Bank Before ACM can do anything, a budget must be prepared and the necessary financial support ...
- HDU 1114 完全背包 HDU 2191 多重背包
HDU 1114 Piggy-Bank 完全背包问题. 想想我们01背包是逆序遍历是为了保证什么? 保证每件物品只有两种状态,取或者不取.那么正序遍历呢? 这不就正好满足完全背包的条件了吗 means ...
- QDUOJ 分辣条-01背包恰好装满情况
分辣条 发布时间: 2016年6月26日 20:36 最后更新: 2016年6月26日 20:37 时间限制: 1000ms 内存限制: 128M 描述 “你喝的酸奶是我买的,辣条也是我买 ...
- HDU 1114 完全背包+判断能否装满
题意 给出一个存钱罐里的钱币重量 给出可能的n种钱币重量以及价值 求存钱罐中钱币的最小价值 若不可能另有输出 在裸的完全背包上加了一点东西 即判断这个背包能否被装满 初始化 dp[0]=0 其余的都使 ...
- hdu 1114(完全背包)
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Piggy-Bank HDU - 1114 完全背包
#include<iostream> #include<cstring> using namespace std; const int INF=0x3f3f3f3f; ]; s ...
- 题解报告:NYOJ #311完全背包(恰好装满)
描述: 直接说题意,完全背包定义有N种物品和一个容量为V的背包,每种物品都有无限件可用.第i种物品的体积是c,价值是w.求解将哪些物品装入背包可使这些物品的体积总和不超过背包容量,且价值总和最大.本题 ...
- ACM_01背包(恰好装满)
背包2 Time Limit: 2000/1000ms (Java/Others) Problem Description: 有n个重量和价值分别为Wi,Vi的物品,现从这些物品中挑选出总量刚好为 W ...
随机推荐
- springboot中文官方文档
springboot中文官方文档 https://www.breakyizhan.com/springboot/3028.html spring框架 https://www.breakyizhan.c ...
- 题解 P3258 【[JLOI2014]松鼠的新家】
树链剖分板子题 先说点别的 小熊维尼啊,嘿嘿嘿. 写题经历 悲惨命运:树剖调了2天,一直90分,死活不AC,调出了心病,快下课时改了一下数据范围,A了--.(刚开始数组开了800100,改120010 ...
- Vivado ILA观察信号和调试过程
先简单介绍一下ILA(Integrated Logic Analyzer)生成方法.这里有两种办法完成Debug Core的配置和实现. 方法一.mark_debug综合选项+Set Up Debug ...
- Activity的生命周期及协同作用
生命周期 onCreate:创建Activity的实例对象的方法 onStart:启动当前的activity实例的方法 onResume:如果该方法执行,页面的实例和用户即可以交互 onPause:如 ...
- STM32CubeIDE 编译C/C++程序
文章转自 https://www.cnblogs.com/skyofbitbit/p/3708216.html STM32CubeIDE 其实就是STM32CubeMx + eclipse 首先,W ...
- C# OBJ模型解析的封装(网上看到的保留一份)
/// <author>Lukas Eibensteiner</author> /// <date>19.02.2013</date> /// < ...
- 简单总结Get与Post的区别
工作当中经常遇到这两种类型的接口,也会被问到这两种类型的区别,这里简单总结一下算是一个简单的回忆吧. GET和POST是http协议的两种发送请求的方法.因为http的底层是TCP/IP,所以GET和 ...
- 10.swoole学习笔记--进程队列通信
<?php //进程仓库 $workers=[]; //最大进程数 $worker_num=; //批量创建进程 ;$i<$worker_num;$i++){ //创建子进程 $proce ...
- Python 中使用 ddt 来进行数据驱动,批量执行用例,修改ddt代码
1. 什么是数据驱动? 使用数据驱动有什么好处? 用例执行是靠数据来驱动的,每条测试用例除了测试数据不一样意外,所有的用例代码都是一样的,为了使用例批量执行,我们会使用数据驱动的思想来批量执行测试用例 ...
- 034-PHP简单定义一个匿名函数
<?php /* 简单定义一个匿名函数 */ # 把匿名函数赋值给一个变量,也叫临时函数 $demo = function ($txt) { echo $txt; }; # 调用测试下 $dem ...