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. HDU_1010——小狗走迷宫DFS

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  2. POJ 1979 深度优先搜索

    题意:有红色和黑色的格子,只能走黑色的,问从起始位置出发,最多能走到达多少块黑色格子. 分析:相当于走迷宫,黑色格子是路,红色格子是墙,每次到达一个未到达过的格子时计数,原点也算是一个.每次可以走上下 ...

  3. PCanywhere/teamviewer/RDP/ultraVNC/tigerVNC/realVNC/Xmanager

    PCanywhere/teamviewer/RDP/ultraVNC/tigerVNC/realVNC/Xmanager 1, 通常应用场景一般CentOS/RHEL等linux系统不配置安装Desk ...

  4. SqlServer 自动备份、自动删除7天前备份

    -----sqlserver 数据异地备份 默认删除 七天前的数据 -----该代码可配置成SQLServer作业里做调度,或者配置成任务计划进行执行 ----挂载异地盘符 exec master.. ...

  5. 解决IE9以下ie版本不能识别新元素的方法 添加一个js -- Shiv Solution

    Thankfully, Sjoerd Visscher created the "HTML5 Enabling JavaScript", "the shiv": ...

  6. Windows移动开发(二)——闭关修炼

    一些武侠小说里的大人物,为了争夺武林盟主,号召天下,常常闭关修炼一段时间,闭关期间仅仅能接触送饭的人,而且关外还有非常多守卫的人员.还有,不管是篮球还是足球运动员,他们在真正接触球之前,都必须做非常长 ...

  7. c++大作业--学籍管理系统--

    1.题目描写叙述 学籍管理系统: 依据信息管理系统的业务流程.要求以及所要实现的目标,完毕下面功能: (1)建立学生档案的管理和维护.实现计算机自己主动化管理体制. (2)建立学生成绩管理机制,在计算 ...

  8. angularjs之双向绑定

    今天所学习的东西虽然不是很多 但是对我来说受益匪浅, 就比如说在table中要选中一行的话我们可以这样写: 模板中: <table ng-controller="tableContro ...

  9. 1.引入必要的文件 2.加载 UI 组件的方式 4.Parser 解析器

    //引入 jQuery 核心库,这里采用的是 2.0 <scripttype="text/javascript"src="easyui/jquery.min.js& ...

  10. InstallShield常用prq文件的下载地址

    VC 2010 redist X86: http://saturn.installshield.com/is/prerequisites/microsoft visual c++ 2010 redis ...