背包形动态规划 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 ...
随机推荐
- 【iOS】duplicate symbols for architecture x86_64
今天遇到了这个问题,错误如下: duplicate symbol _OBJC_IVAR_$_BCViewController.bank in: /Users/***/Library/Developer ...
- jdk1.8源码解析:HashMap底层数据结构之链表转红黑树的具体时机
本文从三个部分去探究HashMap的链表转红黑树的具体时机: 一.从HashMap中有关“链表转红黑树”阈值的声明: 二.[重点]解析HashMap.put(K key, V value)的源码: 三 ...
- 【故障公告】发布 .NET Core 版博客站点引起大量 500 错误
非常抱歉,今天上午的博客站点故障给大家带来了很大的麻烦,请大家谅解.这次故障是我们发布 .NET Core 版博客站点引起的,虽然我们进行了充分的准备,但还是低估了高并发下的复杂问题. 以下是故障背景 ...
- 一文了解:Redis基础类型
Redis基础类型 Redis特点 开源的,BSD许可高级的key-value存储系统 可以用来存储字符串,哈希结构,链表,集合 安装 windows:https://github.com/micro ...
- [NUnit] discover test finished: 0 found issue
%Temp%\VisualStudioTestExplorerExtensions & restart visual studio
- Vue系列:为不同页面设置body背景颜色
由于SPA页面的特性,传统的设置 body 背景色的方法并不通用. 解决方案:利用组件内的路由实现 代码参考如下
- aes秘钥限制问题解决办法
在oarcle jdk1.8上执行256位的aes秘钥加密报错如下: java.lang.RuntimeException: java.security.InvalidKeyException: Il ...
- 深入浅出Apriori关联分析算法(一)
在美国有这样一家奇怪的超市,它将啤酒与尿布这样两个奇怪的东西放在一起进行销售,并且最终让啤酒与尿布这两个看起来没有关联的东西的销量双双增加.这家超市的名字叫做沃尔玛. 你会不会觉得有些不可思议?虽然事 ...
- 日志文件写入失败(permission denied)
用过Laravel的小伙伴一开始安装完框架后可能都遇到过daily 日志文件写入失败的问题,接下来我们就来详细说下日志文件写入失败的原因以及对应的解决方案. 在讲这个问题之前可能需要简单介绍下Linu ...
- 在centos6系列vps装Tomcat8.0
In the following tutorial you will learn how to install and set-up Apache Tomcat 8 on your CentOS 6 ...