洛谷 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--630B--Moore's Law(快速幂)
Moore's Law Time Limit: 500MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64u Submit ...
- 洛谷 P1032 [ NOIP 2002 ] 字串变换 —— 字符串+bfs
题目:https://www.luogu.org/problemnew/show/P1032 字符串好复杂...先写了个 dfs ,RE一个点TLE一个点,不知该怎么改了... #include< ...
- P4135 作诗——分块
题目:https://www.luogu.org/problemnew/show/P4135 分块大法: 块之间记录答案,每一块记录次数前缀和: 注意每次把桶中需要用到位置赋值就好了: 为什么加了特判 ...
- JS判断浏览器类型和详细区分IE各版本浏览器
今天用到JS判断浏览器类型,于是就系统整理了一下,便于后期使用. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ...
- poj3071Football(概率期望dp)
Football Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5620 Accepted: 2868 Descript ...
- web动画小结
前端写动画,无非两种方案,一种是通过css,另一种是js css的方案: 1.transform的单独使用 (IE9+) rotate(90deg) 2d旋转,也可以理解为沿着3D的Z轴旋转 rota ...
- Nginx作为负载均衡服务
负载均衡服务器配置: 注意:upstream和server同级 案例: 建立两个基于端口的虚拟主机来模拟两台web服务器. (1)新建一个www.123.com:81和www.123.com:82的虚 ...
- radis多个盘并发IO
IO就是对磁盘的读/写. 一次IO,就是发出指令+执行命令. 磁盘IO的时间=寻道时间+数据传输时间 单盘不能并发IO. radis多个盘并发IO. 影响IO的最大因素是寻道时间. 影响电脑速度:cp ...
- python--5、包
包 包,即一个包含__init__.py文件的文件夹,创建包的目的也就是为了用文件夹将文件(模块)组织起来.python3中,即使包里没有__init__.py文件,仍能import使用.而pytho ...
- jsp连接MySQL实现登录
1.下载驱动,并把jar包放到Tomcat的lib目录下 下载连接 2.把jar包添加到项目中 3.登录页面 <%@ page language="java" content ...