HDU 1114(没有变形的完全背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1114
Piggy-Bank
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 32136 Accepted Submission(s): 15965
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!
dp[0]=0;
#include<bits/stdc++.h>
#define max_v 10005
using namespace std;
int v[max_v],w[max_v];
int dp[max_v];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int x1,x2,c;
scanf("%d %d",&x1,&x2);
c=abs(x1-x2);
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d %d",&v[i],&w[i]);
}
memset(dp,0x3f,sizeof(dp));//无穷大 //要求恰好装满背包
dp[]=;
for(int i=;i<n;i++)
{
for(int j=w[i];j<=c;j++)
{
dp[j]=min(dp[j],dp[j-w[i]]+v[i]);
}
}
if(dp[c]==dp[max_v-])
{
printf("This is impossible.\n");
}else
{
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[c]);
}
}
return ;
}
HDU 1114(没有变形的完全背包)的更多相关文章
- HDU 1114:Piggy-Bank(完全背包)
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- hdu 1114需要装满的完全背包 重点是背包初始化的问题
.,. 最近在看背包九讲 所以就刷了一下背包的题目 这道题目是一个典型的完全背包问题 而且要求满包 在这里 我就简单整理一下背包初始化问题吧 对于没有要求满包的问题 也就是背包可以不取满的问题 在背包 ...
- HDOJ(HDU).1114 Piggy-Bank (DP 完全背包)
HDOJ(HDU).1114 Piggy-Bank (DP 完全背包) 题意分析 裸的完全背包 代码总览 #include <iostream> #include <cstdio&g ...
- HDU 1114 完全背包 HDU 2191 多重背包
HDU 1114 Piggy-Bank 完全背包问题. 想想我们01背包是逆序遍历是为了保证什么? 保证每件物品只有两种状态,取或者不取.那么正序遍历呢? 这不就正好满足完全背包的条件了吗 means ...
- Piggy-Bank(HDU 1114)背包的一些基本变形
Piggy-Bank HDU 1114 初始化的细节问题: 因为要求恰好装满!! 所以初始化要注意: 初始化时除了F[0]为0,其它F[1..V]均设为−∞. 又这个题目是求最小价值: 则就是初始化 ...
- HDU 1114 Piggy-Bank(一维背包)
题目地址:HDU 1114 把dp[0]初始化为0,其它的初始化为INF.这样就能保证最后的结果一定是满的,即一定是从0慢慢的加上来的. 代码例如以下: #include <algorithm& ...
- hdu 1114 dp动规 Piggy-Bank
Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- HDU 5234 Happy birthday --- 三维01背包
HDU 5234 题目大意:给定n,m,k,以及n*m(n行m列)个数,k为背包容量,从(1,1)开始只能往下走或往右走,求到达(m,n)时能获得的最大价值 解题思路:dp[i][j][k]表示在位置 ...
- 怒刷DP之 HDU 1114
Piggy-Bank Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
随机推荐
- 从敲入 URL 到浏览器渲染完成、对HTTP协议的理解
1. 大致过程 当你这样子回答的时候: 用户输入 url 地址,浏览器查询 DNS 查找对应的请求 IP 地址 建立 TCP 连接 浏览器向服务器发送 http 请求,如果服务器段返回以 301 之类 ...
- 灰度图的直方图均衡化(Histogram Equalization)原理与 Python 实现
原理 直方图均衡化是一种通过使用图像直方图,调整对比度的图像处理方法:通过对图像的强度(intensity)进行某种非线性变换,使得变换后的图像直方图为近似均匀分布,从而,达到提高图像对比度和增强图片 ...
- js滚轮事件
首先,不同的浏览器有不同的滚轮事件.主要是有两种,onmousewheel(firefox不支持)和DOMMouseScroll(只有firefox支持).w3c文档已经废弃了onmousewheel ...
- 选中复选框,才能在文本框中输东西。button按钮已启用,
- 如何利用RMAN Debug和10046 Trace来诊断RMAN问题?
在做Support的这些年,我很大的收获是掌握了许多troubleshooting问题的方法和工具,对于每一类问题,都可以大体归类出一些诊断方法.无论问题多么复杂,像扒洋葱一样,一层层去掉无 ...
- aws rhel 7 安装GUI ,配置VNC
预计阅读时间:15分钟 预计配置时间:30分钟 (前提是已经申请AWS的EC2的rhel7 云主机并且成功运行) 目前AWS 亚马逊云免费试用一年,申请一个学习使用 痛点:没有GUI,无法搭建Jen ...
- [翻译] TCBlobDownload
TCBlobDownload TCBlobDownload uses NSOperations to download large files (typically videos, music... ...
- Springboot 设置session超时
使用版本 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring ...
- symfony学习笔记1—简介
1.symfony快速入门还是先看代码结构把,这个是拿到代码的第一印象,app/:整个应用的配置,模版,translations,这个可能是多语言文件什么,src/:项目php文件,vendor/:第 ...
- 关于Calculator的第四次作业
一.魔法传送门: 问题描述:点我点我点我! 仓库地址:点我点我点我! 二.网上资料: sstream的介绍及应用 后缀表达式C++代码 中缀转前缀及后缀方法 C++计算器源代码 三.实现过程: 在看到 ...