2021: [Usaco2010 Jan]Cheese Towers

Time Limit: 4 Sec  Memory Limit: 64 MB
Submit: 184  Solved: 107
[Submit][Status]

Description

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. John要建一个奶酪塔,高度最大为T。他有N块奶酪。第i块高度为Hi(一定是5的倍数),价值为Vi。一块高度>=K的奶酪被称为大奶酪,一个奶酪如果在它上方有大奶酪(多块只算一次),它的高度就会变成原来的4/5.。。 很显然John想让他的奶酪他价值和最大。。 求这个最大值。。

Input

第一行分别是 N T K 接下来N行分别是 Vi Hi

Output

一行最大值

Sample Input

3 53 25
100 25
20 5
40 10

Sample Output

240

HINT

 

Source

题解:
这题比较有意思。
其实完全两次背包就可以解决,不过还有其他的方法。
做一次容积为 t*5/4的背包,然后 if(h[i]>=k)ans=max(ans,v[i]+f[(t-h[i])*5/4])
好写不容易出错。orz lyd。
代码:
 #include<iostream>
#include<cstdio>
using namespace std;
int a[],b[],f[],n,t,k,m,i,j,ans;
int main()
{
cin>>n>>t>>k;
m=t*/;
for(i=;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
for(i=;i<=n;i++)
for(j=;j<=m-b[i];j++)
f[j+b[i]]=max(f[j+b[i]],f[j]+a[i]);
for(i=;i<=m;i++) f[i]=max(f[i],f[i-]);
ans=f[t];
for(i=;i<=n;i++)
if(b[i]>=k) ans=max(ans,a[i]+f[(t-b[i])*/]);
cout<<ans<<endl;
return ;
}

BZOJ2021: [Usaco2010 Jan]Cheese Towers的更多相关文章

  1. 【BZOJ】2021: [Usaco2010 Jan]Cheese Towers(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2021 噗,自己太弱想不到. 原来是2次背包. 由于只要有一个大于k的高度的,而且这个必须放在最顶,那 ...

  2. BZOJ 2021 [Usaco2010 Jan]Cheese Towers:dp + 贪心

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2021 题意: John要建一个奶酪塔,高度最大为m. 他有n种奶酪.第i种高度为h[i]( ...

  3. BZOJ 2021 Usaco2010 Jan Cheese Towers 动态规划

    题目大意:全然背包.假设最顶端的物品重量≥k,那么以下的全部物品的重量变为原来的45 考虑一些物品装进背包,显然我要把全部重量大于≥k的物品中重量最小的那个放在最顶端.才干保证总重量最小 那么我们给物 ...

  4. 2020: [Usaco2010 Jan]Buying Feed, II

    2020: [Usaco2010 Jan]Buying Feed, II Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 220  Solved: 162[ ...

  5. bzoj 1783: [Usaco2010 Jan]Taking Turns

    1783: [Usaco2010 Jan]Taking Turns Description Farmer John has invented a new way of feeding his cows ...

  6. P2979 [USACO10JAN]奶酪塔Cheese Towers

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

  7. 洛谷 P2979 [USACO10JAN]奶酪塔Cheese Towers

    P2979 [USACO10JAN]奶酪塔Cheese Towers 题目描述 Farmer John wants to save some blocks of his cows' delicious ...

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

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

  9. [bzoj1783] [Usaco2010 Jan]Taking Turns

    题意: 一排数,两个人轮流取数,保证取的位置递增,每个人要使自己取的数的和尽量大,求两个人都在最优策略下取的和各是多少. 注:双方都知道对方也是按照最优策略取的... 傻逼推了半天dp......然后 ...

随机推荐

  1. BZOJ1176---[Balkan2007]Mokia (CDQ分治 + 树状数组)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1176 CDQ第一题,warush了好久.. CDQ分治推荐论文: 1 <从<C ...

  2. flume-agent实例

    flume    多种适配,多样化的数据收集    核心概念        event:一条消息        client:访问者        agent:            重要组件Sour ...

  3. NuGet 问题及小技巧

    在使用NuGet程序包管理时,经常会遇到的一些小问题.比如,联网搜索时间太长,搜索不到常见或想要的程序包,程序包版本兼容问题,想安装制定的版本等. 那么我们可以使用以下的一些小技巧来解决. 1.检查N ...

  4. Android Sensor Test

    魅蓝note可用 [{Sensor name="MPL Gyroscope", vendor="Invensense", version=1, type=4, ...

  5. 命令行修改linux系统IP

    修改配置文件/etc/sysconfig/network-scrips/ifcfg-eth0.因为机子启动的时候加载的就是这个文件的配置参数.对这个文件进行修改:   [root@localhost ...

  6. [React] Extracting Private React Components

    we leverage private components to break our render function into more manageable pieces without leak ...

  7. 基本SQL语句练习之SELECT

    一.SQL Plus连接sqlplus:以命令行方式连接数据库sqlplusw:以窗口登录方式连接数据库conn sys/password as sysdba;show userselect * fr ...

  8. ubantu命令安装banner

    banner命令可以输出图形字符 在线yum安装 $ sudo apt-get update;sudo apt-get install sysvbanner

  9. Node.js中的exports与module.exports的区分

    1. module应该是require方法中,上下文中的对象 2. exports对象应该是上下文中引用module.exports的新对象 3. exports.a = xxx 会将修改更新到mod ...

  10. HTM5新增结构化元素&非结构化元素&新增属性详解

    (1)HTML5 新增的主体结构元素 (2)HTML5 新增的的非主体结构元素 (3)HTML5 表单新增元素与属性 (4)HTML5 改良的 input 元素的种类