http://www.lydsy.com/JudgeOnline/problem.php?id=2021

噗,自己太弱想不到。

原来是2次背包。

由于只要有一个大于k的高度的,而且这个必须放在最顶,那么我们就可以枚举每一个比k大的放在最顶,其它的都放在下边即可。

还有,注意这是完全背包!

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr2(a, b, c) for1(i, 1, b) { for1(j, 1, c) cout << a[i][j]; cout << endl; }
#define printarr1(a, b) for1(i, 1, b) cout << a[i]; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } const int N=105, M=1005;
int f[N][M], n, T, K, w[N], h[N], hh[N], ans; int main() {
read(n); read(T); read(K);
for1(i, 1, n) read(w[i]), read(h[i]), hh[i]=h[i]/5*4;
for1(i, 1, n) if(h[i]<K)
for1(j, h[i], T)
f[0][j]=max(f[0][j], f[0][j-h[i]]+w[i]);
for1(i, 1, n) if(h[i]>=K) {
f[i][h[i]]=w[i];
for1(j, 1, n)
for1(v, h[i]+hh[j], T)
f[i][v]=max(f[i][v], f[i][v-hh[j]]+w[j]);
}
for1(i, 0, n) for1(j, h[i], T) ans=max(ans, f[i][j]);
print(ans);
return 0;
}

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

【BZOJ】2021: [Usaco2010 Jan]Cheese Towers(dp)的更多相关文章

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

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

  2. 【BZOJ】1677: [Usaco2005 Jan]Sumsets 求和(dp/规律)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1677 完全背包很容易想到,将1,2,4...等作为物品容量即可. 然后这题还有一个递推式 f[i]= ...

  3. 【BZOJ】2014: [Usaco2010 Feb]Chocolate Buying(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2014 这应该是显然的贪心吧,先排序,然后按花费取 #include <cstdio> # ...

  4. 【BZOJ】2015: [Usaco2010 Feb]Chocolate Giving(spfa)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2015 这种水题真没啥好说的.. #include <cstdio> #include & ...

  5. 【BZOJ】1600: [Usaco2008 Oct]建造栅栏(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1600 说好的今天开始刷水.. 本题一开始我以为是排列组合,但是自己弱想不出来,只想到了如果四边有一条 ...

  6. 【BZOJ】1801 [Ahoi2009]chess 中国象棋(dp)

    题目 传送门:QWQ 分析 发现我们关心的不是棋子的位置,我们只关心棋子数量就ok. 首先每行每列最多两个棋子.这是显然的. 然后我觉得本题最难的部分就是对行进行讨论,蒟蒻我一直被限制在了对格点讨论. ...

  7. 【BZOJ】3053: The Closest M Points(kdtree)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3053 本来是1a的QAQ.... 没看到有多组数据啊.....斯巴达!!!!!!!!!!!!!!!! ...

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

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

  9. 【BZOJ】2020: [Usaco2010 Jan]Buying Feed, II (dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2020 和背包差不多 同样滚动数组 f[j]表示当前位置j份食物的最小价值 f[j]=min(f[j- ...

随机推荐

  1. ZK框架笔记2、ZK框架安装、相关类库、web及zk配置

    1.先去ZK官网注册一个账号 2.在MyEclipse菜单栏中Help----Eclipse Marketplace中搜索ZK Studio,点击install安装即可         3.相关类库 ...

  2. 【Linux】替换文本中的字符

    替换单个文本中的字符,有两种方法,如下详解 VIM替换 打开文件 vim test.txt 替换 :%s/原字符串/替换字符串/gg 直接替换 sed -i 's/原字符串/替换字符串/g' `ls ...

  3. gulp入门学习教程(入门学习记录)

    前言 最近在通过教学视频学习angularjs,其中有gulp的教学部分,对其的介绍为可以对文件进行合并,压缩,格式化,监听,测试,检查等操作时,看到前三种功能我的心理思想是,网上有很多在线压缩,在线 ...

  4. 多校第九场Arithmetic Sequence题解

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5400 题意:给定等差数列的差值d1,d2.问长度为n的数列中有多少个满足条件的子序列,条件为子序列中 ...

  5. mybatis开发流程,增删改查

    一.开发流程 1)引jar包 //mybatis_core mybatis3.4core\asm-5.2.jar mybatis3.4core\cglib-.jar mybatis3.4core\co ...

  6. atom搭建markdown环境及问题

    1. 搭建markdown环境 > 禁用atom自带的markdown-preview插件(功能简单) > 安装插件:markdown-preview-plus@2.4.16(在markd ...

  7. 编程算法 - 高速排序算法 代码(C)

    高速排序算法 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 经典的高速排序算法, 作为一个编程者, 不论什么时候都要完整的手写. 代码: /* * m ...

  8. Centos下源码安装git

    1.centos下git版本太久了,才1.8几,而官方更新的还是很活跃的,于是我就想源码安装一个新版本. 2.首先到: https://github.com/git/git/releases 下载最新 ...

  9. APK反编译之一:基础知识

    作者:lpohvbe | http://blog.csdn.net/lpohvbe/article/details/7981386 这部分涉及的内容比较多,我会尽量从最基础开始说起,但需要读者一定的a ...

  10. 通过 SysVinit、Systemd 和 Upstart 管理系统自启动进程和服务

    管理 Linux 自启动进程 Linux 系统的启动程序包括多个阶段,每个阶段由一个不同的图示块表示.下面的图示简要总结了启动过程以及所有包括的主要组件. Linux 启动过程 当你按下你机器上的电源 ...