BZOJ2021: [Usaco2010 Jan]Cheese Towers

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

Silver

题解:

这题比较有意思。

其实完全两次背包就可以解决,不过还有其他的方法。

做一次容积为 t*5/4的背包,然后 if(h[i]>=k)ans=max(ans,v[i]+f[(t-h[i])*5/4])

好写不容易出错。orz lyd。

代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 int a[110],b[110],f[2000],n,t,k,m,i,j,ans;
 5 int main()
 6 {
 7     cin>>n>>t>>k;
 8     m=t*5/4;
 9     for(i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
10     for(i=1;i<=n;i++)
11         for(j=0;j<=m-b[i];j++)
12             f[j+b[i]]=max(f[j+b[i]],f[j]+a[i]);
13     for(i=1;i<=m;i++) f[i]=max(f[i],f[i-1]);
14     ans=f[t];
15     for(i=1;i<=n;i++)
16         if(b[i]>=k) ans=max(ans,a[i]+f[(t-b[i])*5/4]);
17     cout<<ans<<endl;
18     return 0;
19 }

时间: 2024-10-21 06:39:27

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

BZOJ 2021 Usaco2010 Jan Cheese Towers 动态规划

题目大意:完全背包,如果最顶端的物品重量≥k,那么下面的所有物品的重量变为原来的45 考虑一些物品装进背包,显然我要把所有重量大于≥k的物品中重量最小的那个放在最顶端,才能保证总重量最小 那么我们给物品排个序,第一键值为重量是否≥k(≥k的放在前面),第二键值为重量(从小到大) 然后依次加入背包,令fi表示没有重量≥k的物品放在最顶端时重量为i的最大价值,gi表示有重量≥k的物品放在最顶端是重量为i的最大价值,DP即可 时间复杂度O(nT) #include <cstdio> #include

2020: [Usaco2010 Jan]Buying Feed, II

2020: [Usaco2010 Jan]Buying Feed, II Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 220  Solved: 162[Submit][Status] Description (buying.pas/buying.in/buying.out 128M 1S) Farmer John needs to travel to town to pick up K (1 <= K <= 100) pounds of feed

洛谷 P2979 [USACO10JAN]奶酪塔Cheese Towers

P2979 [USACO10JAN]奶酪塔Cheese Towers 题目描述 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

bzoj 1783: [Usaco2010 Jan]Taking Turns

1783: [Usaco2010 Jan]Taking Turns Description Farmer John has invented a new way of feeding his cows. He lays out N (1 <= N <= 700,000) hay bales conveniently numbered 1..N in a long line in the barn. Hay bale i has weight W_i (1 <= W_i <= 2,0

P2979 [USACO10JAN]奶酪塔Cheese Towers

题意翻译 题目描述 FJ要建一个奶酪塔,高度最大为T.他有N种奶酪.第i种奶酪的高度为Hi(一定是5的倍数),价值为Vi.一块高度Hi>=K的奶酪被称为大奶酪,一个奶酪如果在它上方有大奶酪(如果有多块就只算一次),它的高度Hi就会变成原来的4/5..FJ想让他的奶酪塔价值和最大.请你求出这个最大值. 输入格式: 第一行三个数N,T,K,意义如上所述. 接下来n行,每行两个数V_i,h_i(注意顺序) 输出格式: 奶酪塔的最大价值 题目描述 Farmer John wants to save so

BZOJ1783: [Usaco2010 Jan]Taking Turns

n<=700000个数,两人轮流取数,位置必须单增,输出两人都按最优策略得到的最大答案. 一开始看不懂"最优策略",后来发现没有必要知道,f[i][1/0]--先/后手取数i最优答案,f[i][1]=a[i]+f[maxi][0],f[i][0]=f[maxi][1],maxi>i,因为先手取完后手必定转移到后面最优的先手策略. 然后WA了一发.这两人还是挺友好的不会陷害对方,就是说,有多个f[maxi][1]时,去下标最小的一个,让游戏进行地更持久! 1 #include

bzoj1784: [Usaco2010 Jan]island

现在居然出现一道题只有\(pascal\)题解没有\(C++\)题解的情况,小蒟蒻要打破它. 思维题:分类讨论 回归正题,此题十分考验思维,首先我们要考虑如何把不会走的地方给填上,使最后只用求一遍这个图的周长即可.考虑目标点的几种情况: \(0.\)当前点周围有三个\(A\)或四个\(A\)时:这个点肯定不会走到,直接用\(A\)填上. \(1.\)当前点夹在两个点中间,无法判断这个点被填上后是否会让两边出现独立的\(x\),所以跳过该点,之后如果某一边被填满,会导致这个点被重新搜到,那时再考虑

小结:动态规划

概要: 状态.转移:最优子结构.无后效性. 技巧及注意: dp就是纯经验+智商题 在dp方程写出来后,一定要考虑边界!不要以为转移对了就行了! 滚动数组的话一定要考虑好顺序! 下标有时候可以灵活使用!比如mod意义下的dp,倍数什么.可到达性等题目都可以这样做. 如果是线性序列的max{f[k]},k<i这种可以用线段树或bit维护成log 注意“前i”和“第i”的区别(特别对于答案更新),有时换一种就能解答出问题. 在状态加限制条件,如单调.地址等. 用下标来维护下标这个答案是否可达. 博弈论

bzoj usaco 金组水题题解(1)

UPD:我真不是想骗访问量TAT..一开始没注意总长度写着写着网页崩了王仓(其实中午的时候就时常开始卡了= =)....损失了2h(幸好长一点的都单独开了一篇)....吓得赶紧分成两坨....TAT.............. —————————————————————————————————————————————————————————————————————————————— 写(被虐)了整整一个月b站上usaco的金组题...然而到现在总共只写了100道上下TAT(当然是按AC人数降序排