题目描述

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. (Go)09.指针赋值修改示例

      答案: 1 package main 2 import ( 3 "fmt" 4 ) 5 6 7 func modify(p *int) { 8 fmt.Println(p) 9 ...

  2. selenium3 + python 操作浏览器基本方法

    from selenium import webdriverimport time as t # driver = webdriver.Chrome()# driver.get("http: ...

  3. 通过委托事件实现winform窗体之间的互相刷新

    新建winform窗体Form1和Form2; 接下来要通过点击Form2的按钮,实现Form1界面的同步刷新. 先展示一下最终效果: 1.Form1界面如下: 2.点击按钮弹出Form2,界面如下: ...

  4. Struts2 在登录拦截器中对ajax请求的处理

    前言: 由于ajax请求不像http请求,可以直接进行页面跳转,你返回的所有东西,ajax都只会识别为一个字符串. 之前尝试的方法是在拦截器中返回一个标识给ajax,然后再在每一个ajax请求成功之后 ...

  5. matplotlib之pyplot 学习示例

    现在通过numpy和matplotlib.pyplot 在Python上实现科学计算和绘图,而且和matlab极为相像(效率差点,关键是方便简单) 这里有大量plots代码例子.  1. 简单的绘图( ...

  6. jQuery 滑动及点击切换效果

    效果图如下: 初始化 hover效果:滑动menuitem,‘首页’不变,字体颜色改变,有下划线展示. 即在动态添加boder-bottom,改变字体颜色颜色 .menuItem:hover{ bor ...

  7. Android fragment的切换(解决REPLACE的低效)

    在项目中切换Fragment,一直都是用replace()方法来替换Fragment.但是这样做有一个问题,每次切换的时候Fragment都会重新实列化,重新加载一次数据,这样做会非常消耗性能用用户的 ...

  8. HTML 5概述

    HTML语言是一种简易的文件交换标准,用于物理的文件结构,它旨在定义文件内的对象和描述文件的逻辑结构,而并不定义文件的显示.由于HTML所描述的文件具有极高的适应性,所以特别适合于WWW的出版环境. ...

  9. 酷派改变者S1(C105/C105-6/C105-8) 解锁BootLoader 并刷入recovery root

    首先下载好工具链接:https://pan.baidu.com/s/1qZjOCUw 密码:u2dr 备用下载链接:https://pan.baidu.com/s/1pMlmAef 本篇教程教你如何傻 ...

  10. 指定DIV局部刷新的简单实现,很简单,但是网上搜到的大部分都很复杂

    脚本部分: <script type="text/javascript"> $(function () { setInterval(function () { $(&q ...