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. sicily 1024 Magic Island

    题意:求无向图路径中的最大带权值. 解法:深搜 // Problem#: 9859 // Submission#: 2661875 // The source code is licensed und ...

  2. 【转】 基于TFTP协议的远程升级设计

    版权声明:本文为博主原创文章,未经博主允许不得转载.联系邮箱:zhzhchang@126.com 说明:由于CSDN博客编辑器对word格式近乎不支持,因此对表格使用了图片方式(最后一个表格未使用图片 ...

  3. JS-异常处理

    自定义异常: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <ti ...

  4. [Qt]No relevant classes found.

    [Qt]No relevant classes found. 我把两个文件加入工程的时候,再编译就出现了No relevant classes found.这个bug.百度了下,找到了答案,参考链接: ...

  5. C#中对于接口的实现方式

    转载: C#中对于接口的实现方式有隐式接口和显式接口两种: 隐式地实现接口成员创建一个接口,IChinese,包含一个成员 Speak;我们创建一个类Speaker,实现接口Chinese //隐藏式 ...

  6. jQuery 左侧滑动

    $("#slideleft button").click(function(){ var $lefty = $(this).next(); $lefty.animate({ lef ...

  7. TTTAttributedLabel使用介绍(转)

    TTTAttributedLabel 库地址 https://github.com/TTTAttributedLabel/TTTAttributedLabel 可以实现电话  地址  链接自动查找显示 ...

  8. android后台截屏实现(3)--编译screencap

    修改好之后就要编译了,screencap的编译是要在源码环境中进行的. 将修改后的screencap.cpp文件替换源码中的原始文件,然后修改screencap的Android.mk文件,修改后的文件 ...

  9. POJ 2175 Evacuation Plan (费用流,负环,消圈法,SPFA)

    http://poj.org/problem?id=2175 Evacuation Plan Time Limit: 1000MS   Memory Limit: 65536K Total Submi ...

  10. [React Testing] className with Shallow Rendering

    The React Shallow Renderer test utility lets us inspect the output of a component one level deep. In ...