题目描述

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

输入输出样例

输入样例#1:

3 53 25
100 25
20 5
40 10
输出样例#1:

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的更多相关文章

  1. P2979 [USACO10JAN]奶酪塔Cheese Towers

    P2979 [USACO10JAN]奶酪塔Cheese Towers 背包dp 不过多了一个大奶酪可以压扁其他奶酪的 一开始写了个暴力82分.贪心的选择 然后发现,有如下两种规律 要么最优都是小奶酪, ...

  2. P2979 [USACO10JAN]奶酪塔Cheese Towers(完全背包,递推)

    题目描述 Farmer John wants to save some blocks of his cows' delicious Wisconsin cheese varieties in his ...

  3. 洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II

    洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II https://www.luogu.org/problemnew/show/P2616 题目描述 Farmer ...

  4. 洛谷 P2978 [USACO10JAN]下午茶时间Tea Time

    P2978 [USACO10JAN]下午茶时间Tea Time 题目描述 N (1 <= N <= 1000) cows, conveniently numbered 1..N all a ...

  5. BZOJ2021: [Usaco2010 Jan]Cheese Towers

    2021: [Usaco2010 Jan]Cheese Towers Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 184  Solved: 107[Su ...

  6. 洛谷1640 bzoj1854游戏 匈牙利就是又短又快

    bzoj炸了,靠离线版题目做了两道(过过样例什么的还是轻松的)但是交不了,正巧洛谷有个"大牛分站",就转回洛谷做题了 水题先行,一道傻逼匈牙利 其实本来的思路是搜索然后发现写出来类 ...

  7. 洛谷P1352 codevs1380 没有上司的舞会——S.B.S.

    没有上司的舞会  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description Ural大学有N个职员,编号为1~N.他们有 ...

  8. 洛谷P1108 低价购买[DP | LIS方案数]

    题目描述 “低价购买”这条建议是在奶牛股票市场取得成功的一半规则.要想被认为是伟大的投资者,你必须遵循以下的问题建议:“低价购买:再低价购买”.每次你购买一支股票,你必须用低于你上次购买它的价格购买它 ...

  9. 洛谷 P2701 [USACO5.3]巨大的牛棚Big Barn Label:二维数组前缀和 你够了 这次我用DP

    题目背景 (USACO 5.3.4) 题目描述 农夫约翰想要在他的正方形农场上建造一座正方形大牛棚.他讨厌在他的农场中砍树,想找一个能够让他在空旷无树的地方修建牛棚的地方.我们假定,他的农场划分成 N ...

随机推荐

  1. codeforces 899F Letters Removing set+树状数组

    F. Letters Removing time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. c++ valarray 实现矩阵与向量相乘

    #include <iostream>#include <valarray> template<class T> class Slice_iter { std::v ...

  3. git 设定全局ignore

    创建: 2017/08/08   位置: $HOME/.config/git/ignore git/ignore 要自建 内容  https://github.com/github/gitignore ...

  4. windows php文件下载地址

    http://windows.php.net/downloads/releases/archives/

  5. Python 38 初识数据库

    数据库 1.什么是mysql,什么是数据库? 文件处理就可以将数据永久存储 问题 1.管理不方便 2.文件操作效率问题 3.一个程序不太可能仅运行在同一台电脑上 提高计算机性能的方式 1.垂直扩展  ...

  6. ROS-TF-Time

    前言:如何在特定时间进行转换.让第二只乌龟去第一只乌龟在5秒前的地方. 参考自:http://wiki.ros.org/tf/Tutorials/Time%20travel%20with%20tf%2 ...

  7. JavaScript 进阶 常用内置对象

    一.常用内置对象 所谓内置对象就是ECMAscript提供出来的一些对象,我们知道对象都是有相应的属性和方法 数组Arry 1.数组的创建方式 字面量方式创建(推荐使用,简单粗暴) var color ...

  8. Asp.net三种事务处理

    事务处理是在数据处理时经常遇到的问题,经常用到的方法有以下三种总结整理如下:方法1:直接写入到sql 中在存储过程中使用 BEGIN TRANS, COMMIT TRANS, ROLLBACK TRA ...

  9. 【转】国外程序员整理的 PHP 资源大全

      iadoz 在 Github 发起维护的一个 PHP 资源列表,内容包括:库.框架.模板.安全.代码分析.日志.第三方库.配置工具.Web 工具.书籍.电子书.经典博文等等. 依赖管理 依赖和包管 ...

  10. Flutter GitLab 客户端

    F4Lab Flutter for GitLab. 欢迎参加一起完成