背包形动态规划 fjutoj1380 Piggy-Bank
Piggy-Bank
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!
3
10 110
2
1 1
30 50
10 110
2
1 1
50 30
1 6
2
10 3
20 4
The minimum amount of money in the piggy-bank is 60.
The minimum amount of money in the piggy-bank is 100.
This is impossible. 思路:裸的完全背包
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn = ;
int weight[maxn], value[maxn];
int dp[][];
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
memset(weight,,sizeof(weight));
memset(value,,sizeof(value));
memset(dp,INF,sizeof(dp));
int v1,v2,v;
scanf("%d%d",&v1,&v2);
v=v2-v1;
int m;
scanf("%d",&m);
for(int i=; i<=m; i++)
scanf("%d%d",&value[i],&weight[i]);
dp[][]=;
for(int i=; i<=m; i++)
{
for(int j=; j<=v; j++)
dp[i][j]=dp[i-][j];
for(int j=weight[i]; j<=v; j++)
dp[i][j]=min(dp[i][j], dp[i][j-weight[i]] + value[i] ) ; }
if(dp[m][v]!=INF)
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[m][v]);
else
printf("This is impossible.\n");
}
return ;
}
背包形动态规划 fjutoj1380 Piggy-Bank的更多相关文章
- 背包形动态规划 fjutoj2347 采药
采药 TimeLimit:1000MS MemoryLimit:128MB 64-bit integer IO format:%lld Problem Description 辰辰是个天资聪颖的 ...
- 背包形动态规划 fjutoj2375 金明的预算方案
金明的预算方案 TimeLimit:1000MS MemoryLimit:128MB 64-bit integer IO format:%lld Problem Description 金明今天 ...
- CJOJ 2040 【一本通】分组背包(动态规划)
CJOJ 2040 [一本通]分组背包(动态规划) Description 一个旅行者有一个最多能用V公斤的背包,现在有n件物品,它们的重量分别是W1,W2,...,Wn,它们的价值分别为C1,C2, ...
- CJOJ 2307 【一本通】完全背包(动态规划)
CJOJ 2307 [一本通]完全背包(动态规划) Description 设有n种物品,每种物品有一个重量及一个价值.但每种物品的数量是无限的,同时有一个背包,最大载重量为M,今从n种物品中选取若干 ...
- 【BZOJ5302】[HAOI2018]奇怪的背包(动态规划,容斥原理)
[BZOJ5302][HAOI2018]奇怪的背包(动态规划,容斥原理) 题面 BZOJ 洛谷 题解 为啥泥萌做法和我都不一样啊 一个重量为\(V_i\)的物品,可以放出所有\(gcd(V_i,P)\ ...
- nyist oj 311 全然背包 (动态规划经典题)
全然背包 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描写叙述 直接说题意,全然背包定义有N种物品和一个容量为V的背包.每种物品都有无限件可用.第i种物品的体积是c,价值是 ...
- 【Python】0/1背包、动态规划
0/1背包问题:在能承受一定重量的背包中,放入重量不同,价值不同的几件物品,怎样放能让背包中物品的价值最大? 比如,有三件物品重量w,价值v分别是 w=[5,3,2] v=[9,7,8] 包的容量是5 ...
- 【背包型动态规划】灵魂分流药剂(soultap) 解题报告
问题来源 BYVoid魔兽世界模拟赛 [问题描述] 皇家炼金师赫布瑞姆刚刚发明了一种用来折磨一切生物的新产品,灵魂分流药剂.灵魂分流药剂的妙处在于能够给服用者带来巨大的痛苦,但是却不会让服用者死去,而 ...
- 0-1背包的动态规划算法,部分背包的贪心算法和DP算法------算法导论
一.问题描述 0-1背包问题,部分背包问题.分别实现0-1背包的DP算法,部分背包的贪心算法和DP算法. 二.算法原理 (1)0-1背包的DP算法 0-1背包问题:有n件物品和一个容量为W的背包.第i ...
随机推荐
- WebSocket的实现与应用
WebSocket的实现与应用 前言 说到websocket,就不得不提http协议的连接特点特点与交互模型. 首先,http协议的特点是无状态连接.即http的前一次连接与后一次连接是相互独立的. ...
- 开发一个Spring Boot Starter!
在上一篇文章中,我们已经了解了一个starter实现自动配置的基本流程,在这一小结我们将复现上一过程,实现一个自定义的starter. 先来分析starter的需求: 在项目中添加自定义的starte ...
- Hadoop单机、伪分布式、分布式集群搭建
JDK安装 设置hostname [root@bigdata111 ~]# vi /etc/hostname 设置机器hosts [root@bigdata111 ~]# vi /etc/hosts ...
- python3学习-requests使用
前面我们讲过了urllib模块,知道他是用于网络请求的,这一节讲的requests还是用于网络请求的,只不过urllib是官方模块,而requests是第三方的模块.用过的人都说他才是'人类使用的', ...
- Promise 学习心得
当了这么久码农到今天没事才开始去深究 Promise 这个对象 什么是 Promise, Promise 有什么用? 在写代码的时候多多少少都有遇见过地狱式的回调 代码看起来没问题就是有点乱,Prom ...
- 【PYTHON】语法基础 | 开始使用Python
Python的热度不言而喻,机器学习.数据分析的首选语言都是Python,想要学习Python的小伙伴也很多,我之前也没有认真用过Python,所以也想体验一下它的魅力,索性花了两天集中看了一下它的基 ...
- 压力测试-jmeter
1. 场景描述 新申请的服务器,要压测下python算法程序最多能执行多少条数据,有几年没用压力测试工具-jmeter了,重新下载了最新版本,记录下,也希望能帮到准备使用jmeter做压测的朋友. 2 ...
- python面试总结1(基础章节)
python语言基础 语言特点 python是静态还是动态类型?是强类型还是弱类型 动态强类型语言 动态还是静态指的是编译期还是运作期确定类型 强类型指的是不会发生隐式类型转换 python作为后端语 ...
- Android OTG之USB转串口模块通讯
微信公众号:CodingAndroid CSDN:http://blog.csdn.net/xinpengfei521 1.背景简介 我们公司开发了一款室内机平板APP应用,要求平板能去控制智能门锁. ...
- 提取html内的文字1
public static string StripHTML(string strHtml) { string [] aryReg ={ @"<scrip ...