【BZOJ】2021: [Usaco2010 Jan]Cheese Towers(dp)
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
Input
Output
Sample Input
100 25
20 5
40 10
Sample Output
HINT
Source
【BZOJ】2021: [Usaco2010 Jan]Cheese Towers(dp)的更多相关文章
- BZOJ 2021 [Usaco2010 Jan]Cheese Towers:dp + 贪心
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2021 题意: John要建一个奶酪塔,高度最大为m. 他有n种奶酪.第i种高度为h[i]( ...
- 【BZOJ】1677: [Usaco2005 Jan]Sumsets 求和(dp/规律)
http://www.lydsy.com/JudgeOnline/problem.php?id=1677 完全背包很容易想到,将1,2,4...等作为物品容量即可. 然后这题还有一个递推式 f[i]= ...
- 【BZOJ】2014: [Usaco2010 Feb]Chocolate Buying(贪心)
http://www.lydsy.com/JudgeOnline/problem.php?id=2014 这应该是显然的贪心吧,先排序,然后按花费取 #include <cstdio> # ...
- 【BZOJ】2015: [Usaco2010 Feb]Chocolate Giving(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=2015 这种水题真没啥好说的.. #include <cstdio> #include & ...
- 【BZOJ】1600: [Usaco2008 Oct]建造栅栏(dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1600 说好的今天开始刷水.. 本题一开始我以为是排列组合,但是自己弱想不出来,只想到了如果四边有一条 ...
- 【BZOJ】1801 [Ahoi2009]chess 中国象棋(dp)
题目 传送门:QWQ 分析 发现我们关心的不是棋子的位置,我们只关心棋子数量就ok. 首先每行每列最多两个棋子.这是显然的. 然后我觉得本题最难的部分就是对行进行讨论,蒟蒻我一直被限制在了对格点讨论. ...
- 【BZOJ】3053: The Closest M Points(kdtree)
http://www.lydsy.com/JudgeOnline/problem.php?id=3053 本来是1a的QAQ.... 没看到有多组数据啊.....斯巴达!!!!!!!!!!!!!!!! ...
- BZOJ 2021 Usaco2010 Jan Cheese Towers 动态规划
题目大意:全然背包.假设最顶端的物品重量≥k,那么以下的全部物品的重量变为原来的45 考虑一些物品装进背包,显然我要把全部重量大于≥k的物品中重量最小的那个放在最顶端.才干保证总重量最小 那么我们给物 ...
- 【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- ...
随机推荐
- WCF 之 概述
WCF全称是Windows Communication Foundation,它是.NET3.0的重要组成部分,用来解决Windows下的一些通信方面的问题.WCF是Microsoft平台上的SOA架 ...
- Android NDK 交叉编译C++代码生成.so共享库详细步骤
Android NDK 交叉编译C++代码生成.so共享库详细步骤 Android NDK 调用c++ stl 模板库(修改android.mk文件) 1 在需要调用模板库的文件前包含头文件: ...
- C++ STL中Map的按Key排序
为了实现快速查找,map内部本身就是按序存储的(比如红黑树).在我们插入<key, value>键值对时,就会按照key的大小顺序进行存储.这也是作为key的类型必须能够进行<运算比 ...
- VBA验证工作表是否存在
使用VBA验证工作表是否存在 ============================================================= 代码区域 ================== ...
- 01-hibernate注解:类级别注解,@Entity,@Table,@Embeddable
@Entity @Entity:映射实体类 @Entity(name="tableName") name:可选,对应数据库中一个表,若表名与实体类名相同,则可以省略. 注意:使用@ ...
- PHP 导出 CSV 文件用 Excel 打开出现中文乱码
本篇文章由:http://xinpure.com/php-export-csv-file-opened-by-excel-appear-garbled/ 乱码情况 写了一段导出 CSV 文件的代码,可 ...
- 动态规划初级 入门理解 C#代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Micros ...
- 自定义闹钟 Reminder
Reminder reminder = ScheduledActionService.Find("MY REMINDER") as Reminder; if ( reminder ...
- 爱国者布局智能硬件,空探系列PM2.5检測仪“嗅霾狗”大曝光
随着6月1日史上最严禁烟令的正式实施,国内包含北京.上海.成都等大中型城市已经在公共场所全面禁烟.众所周知,实施禁烟令的根本在于促进空气的净化,实现环境的改善,要达到这个目的,光有禁烟令是远远 ...
- (WPF)依赖属性
属性触发器: <Button MinWidth=" 75" Margin="10"> <Button.Style> <Style ...