洛谷 P2979 [USACO10JAN]奶酪塔Cheese Towers
题目描述
Farmer John wants to save some blocks of his cows' delicious Wisconsin cheese varieties in his cellar for the coming winter. He has room for one tower of cheese in his cellar, and that tower's height can be at most T (1 <= T <= 1,000). The cows have provided him with a virtually unlimited number of blocks of each kind of N (1 <= N <= 100) different types of cheese (conveniently numbered 1..N). He'd like to store (subject to the constraints of height) the most
valuable set of blocks he possibly can. The cows will sell the rest to support the orphan calves association.
Each block of the i-th type of cheese has some value V_i (1 <= V_i <= 1,000,000) and some height H_i (5 <= H_i <= T), which is always a multiple of 5.
Cheese compresses. A block of cheese that has height greater than or equal to K (1 <= K <= T) is considered 'large' and will crush any and all of the cheese blocks (even other large ones) located below it in the tower. A crushed block of cheese doesn't lose any value, but its height reduces to just 4/5 of its old height. Because the height of a block of cheese is always a multiple of 5, the height of a crushed block of cheese will always be an integer. A block of cheese is either crushed or not crushed; having multiple large blocks above it does not crush it more. Only tall blocks of cheese crush other blocks; aggregate height of a tower does not affect whether a block is crushed or not.
What is the total value of the best cheese tower FJ can construct?
Consider, for example, a cheese tower whose maximum height can be 53 to be build from three types of cheese blocks. Large blocks are those that are greater than or equal to 25. Below is a chart of the values and heights of the various cheese blocks he stacks:
Type Value Height
1 100 25
2 20 5
3 40 10
FJ constructs the following tower:
Type Height Value
top -> [1] 25 100
[2] 4 20 <- crushed by [1] above
[3] 8 40 <- crushed by [1] above
[3] 8 40 <- crushed by [1] above
bottom -> [3] 8 40 <- crushed by [1] above
The topmost cheese block is so large that the blocks below it are crushed. The total height is:
25 + 4 + 8 + 8 + 8 = 53
The total height does not exceed 53 and thus is 'legal'. The total value is:
100 + 20 + 40 + 40 + 40 = 240.
This is the best tower for this particular set of cheese blocks.
要建一个奶酪塔,高度最大为T。他有N块奶酪。第i块高度为Hi(一定是5的倍数),价值为Vi。一块高度>=K的奶酪被称为大奶酪,一个奶酪如果在它上方有大奶酪(多块只算一次),它的高度就会变成原来的4/5.。 很显然John想让他的奶酪他价值和最大。求这个最大值。
输入输出格式
输入格式:
Line 1: Three space-separated integers: N, T, and K
- Lines 2..N+1: Line i+1 contains two space separated integers: V_i and H_i
输出格式:
- Line 1: The value of the best tower FJ can build
输入输出样例
3 53 25
100 25
20 5
40 10
240
思路:如果没有大奶酪,这个题目可以看成是完全背包来做。但是加上了大奶酪,所以就把状况分开,把大奶酪和没有大奶酪分开来看。
如果没有大奶酪:f[j][0]=max(f[j][0],f[j-h[i]][0]+v[i]);
如果某个奶酪上能放大奶酪,即f[j-w[i]*4/5][1]存在解:f[j][1]=max(f[j][1],f[j-w[i]*4/5][1]+v[i]);
如果没聚到某个奶酪正好是大奶酪:f[j][1]=max(f[j][1],f[(j-w[i])*4/5][0]+v[i]);
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int T,n,k,tot,f[][];
struct nond{
int v,h;
}nl[];
int cmp(nond x,nond y){
return x.h>y.h;
}
int cmp1(nond x,nond y){
return x.h<y.h;
}
int main(){
scanf("%d%d%d",&n,&T,&k);
for(int i=;i<=n;i++){
scanf("%d%d",&nl[i].v,&nl[i].h);
if(nl[i].h>=k) tot++;
}
sort(nl+,nl++n,cmp);
sort(nl+,nl++tot,cmp1);
for(int i=;i<=T;i++) f[i][]=-;
for(int i=;i<=n;i++)
for(int j=nl[i].h;j<=T;j++){
f[j][]=max(f[j][],f[j-nl[i].h][]+nl[i].v);
if(f[j-nl[i].h*/][]!=-) f[j][]=max(f[j][],f[j-nl[i].h*/][]+nl[i].v);
if(nl[i].h>=k) f[j][]=max(f[j][],f[(j-nl[i].h)*/][]+nl[i].v);
}
cout<<max(f[T][],f[T][]);
}
洛谷 P2979 [USACO10JAN]奶酪塔Cheese Towers的更多相关文章
- P2979 [USACO10JAN]奶酪塔Cheese Towers
P2979 [USACO10JAN]奶酪塔Cheese Towers 背包dp 不过多了一个大奶酪可以压扁其他奶酪的 一开始写了个暴力82分.贪心的选择 然后发现,有如下两种规律 要么最优都是小奶酪, ...
- P2979 [USACO10JAN]奶酪塔Cheese Towers(完全背包,递推)
题目描述 Farmer John wants to save some blocks of his cows' delicious Wisconsin cheese varieties in his ...
- 洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II
洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II https://www.luogu.org/problemnew/show/P2616 题目描述 Farmer ...
- 洛谷 P2978 [USACO10JAN]下午茶时间Tea Time
P2978 [USACO10JAN]下午茶时间Tea Time 题目描述 N (1 <= N <= 1000) cows, conveniently numbered 1..N all a ...
- BZOJ2021: [Usaco2010 Jan]Cheese Towers
2021: [Usaco2010 Jan]Cheese Towers Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 184 Solved: 107[Su ...
- 洛谷1640 bzoj1854游戏 匈牙利就是又短又快
bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...
- 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.
没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...
- 洛谷P1108 低价购买[DP | LIS方案数]
题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...
- 洛谷 P2701 [USACO5.3]巨大的牛棚Big Barn Label:二维数组前缀和 你够了 这次我用DP
题目背景 (USACO 5.3.4) 题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N ...
随机推荐
- Codeforces--630C--Lucky Numbers(快速幂)
C - Lucky Numbers Crawling in process... Crawling failed Time Limit:500MS Memory Limit:65536K ...
- B5248 [2018多省省队联测]一双木棋 状压dp
这个题当时划水,得了二十分,现在来整一整. 这个题用状压来压缩边界线,然后通过记忆化搜索进行dp.我们可以观察到,其实每次转移,就是把一个1向左移一位.最后的状态设为0. 这其中还要有一个变量来记录谁 ...
- 莫队&&分块
今天兔哥讲了一波莫队,比较有趣,先加一个链接,这是她的教程 rabbithu.cnblogs.com 这里就不详细说了,其实就是两个指针来优化的暴力.一开始排序函数有问题,没用上莫队的核心思想:把查询 ...
- 86. Ext文本输入框:Ext.form.TextField属性汇总
转自:https://blog.csdn.net/ryuudenne/article/details/8834650 Ext.form.TextField主要配置表: allowBlank ...
- 使用 Polyfill 而不再是 bable 来实践js新特性
现状 我们想要用ES6 语法来写 JavaScript.然而由于我们需要兼容老版本的浏览器,那些浏览器不支持 ES6,我们需要解决这个问题. 有一个标准的做法是:写 ES6 代码 → 将所有代码编译成 ...
- SiteMesh3使用实例和详解
一.SiteMesh介绍 SiteMesh是一个网页布局和修饰的框架,利用它可以将网页的内容和页面结构分离,以达到页面结构共享的目的.[来自百度百科] 通俗的理解就是,SiteMesh把页面中变化的和 ...
- [Apple开发者帐户帮助]二、管理你的团队(7)管理服务器帐户
如果在配置机器人以在多个设备上运行应用程序时向团队添加服务器,允许Xcode Server为您管理签名,或者配置机器人以创建iOS App文件,则服务器可以访问您的资产并显示在您的开发人员帐户 您可以 ...
- golang 获取statuscode
最近日志打印的时候需要打印状态码,但是因为interface的原因直接获取失败,http.Request里面的response不知道怎么使用,所以就自己重写writeheader,write来截取st ...
- 利用 Puppet 实现自动化管理配置 Linux 计算机集群
随着虚拟化和云计算技术的兴起,计算机集群的自动化管理和配置成为了数据中心运维管理的热点.对于 IaaS.Paas.Saas 来说,随着业务需求的提升,后台计算机集群的数量也会线性增加.对于数据中心的运 ...
- B - Link/Cut Tree
Problem description Programmer Rostislav got seriously interested in the Link/Cut Tree data structur ...