题目描述

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.
要建一个奶酪塔,高度最大为T。他有N块奶酪。第i块高度为Hi(一定是5的倍数),价值为Vi。一块高度>=K的奶酪被称为大奶酪,一个奶酪如果在它上方有大奶酪(多块只算一次),它的高度就会变成原来的4/5.。 很显然John想让他的奶酪他价值和最大。求这个最大值。

输入输出格式

输入格式:

* Line 1: Three space-separated integers: N, T, and K

* Lines 2..N+1: Line i+1 contains two space separated integers: V_i and H_i

输出格式:

* Line 1: The value of the best tower FJ can build

输入输出样例

输入样例#1: 复制

3 53 25
100 25
20 5
40 10
输出样例#1: 复制

240 

题意:

完全背包,如果当前奶酪的顶上还有符合条件的大奶酪时,当前奶酪的体积变成原来体积的$\frac{4}{5}$。

那么根据题目的意思,对于当前第i种奶酪,在他之前分为已经放了大奶酪和没放大奶酪两种情况来考虑,设f[j][0]表示当前体积为j,且之前没有放大奶酪;f[j][1]表示当前体积为j,且之前已经了放大奶酪

  • 如果之前放了大奶酪,那么可以从f[j][1]转化到f[j+h[i]/5*4][1]
  • 如果之前没有放大奶酪,且当前这个奶酪也不是大奶酪,那么可以从f[j][0]转化到f[j+h[i]][0]
  • 如果之前没有放大奶酪,而当前这个奶酪恰好是大奶酪,那么可以从f[j][0]转化到f[j+h[i]][1]
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int f[1010][2];//体积,之前是否有大奶酪
int h[110],v[110];
int main() {
// freopen("C:/Users/Xzq/Desktop/p1.txt","r",stdin);
int n,t,k;
scanf("%d %d %d",&n,&t,&k);
for(int i=1; i<=n; i++) scanf("%d %d",&v[i],&h[i]);
memset(f,-1,sizeof(f));
//f[j][0],体积为j,之前没有大奶酪
//f[j][1],体积为j,之前有大奶酪
f[0][0]=0;//初始条件 for(int j=0;j<=t;j++){
for(int i=1;i<=n;i++){
//不是大奶酪,之前也没有大奶酪
if(j+h[i]<=t&&f[j][0]!=-1) f[j+h[i]][0]=max(f[j+h[i]][0],f[j][0]+v[i]);
//不是大奶酪,之前有大奶酪
if(j+h[i]/5*4<=t&&f[j][1]!=-1) f[j+h[i]/5*4][1]=max(f[j+h[i]/5*4][1],f[j][1]+v[i]);
//之前没有大奶酪,即将放上大奶酪
if(h[i]>=k&&f[j][0]!=-1&&h[i]+j<=t) f[h[i]+j][1]=max(f[h[i]+j][1],f[j][0]+v[i]);
}
} int ans=0;
for(int i=1;i<=t;i++) ans=max(ans,max(f[i][0],f[i][1])); printf("%d\n",ans);
return 0;
}

P2979 [USACO10JAN]奶酪塔Cheese Towers(完全背包,递推)的更多相关文章

  1. P2979 [USACO10JAN]奶酪塔Cheese Towers

    P2979 [USACO10JAN]奶酪塔Cheese Towers 背包dp 不过多了一个大奶酪可以压扁其他奶酪的 一开始写了个暴力82分.贪心的选择 然后发现,有如下两种规律 要么最优都是小奶酪, ...

  2. 洛谷 P2979 [USACO10JAN]奶酪塔Cheese Towers

    P2979 [USACO10JAN]奶酪塔Cheese Towers 题目描述 Farmer John wants to save some blocks of his cows' delicious ...

  3. UVA11137 Ingenuous Cubrency 完全背包 递推式子

    做数论都做傻了,这道题目 有推荐,当时的分类放在了递推里面,然后我就不停的去推啊推啊,后来推出来了,可是小一点的数 输出答案都没问题,大一点的数 输出答案就是错的,实在是不知道为什么,后来又不停的看, ...

  4. POJ1958 Strange Towers of Hanoi [递推]

    题目传送门 Strange Towers of Hanoi Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3117   Ac ...

  5. BZOJ 1677 [Usaco2005 Jan]Sumsets 求和:dp 无限背包 / 递推【2的幂次方之和】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1677 题意: 给定n(n <= 10^6),将n分解为2的幂次方之和,问你有多少种方 ...

  6. 【POJ】2229 Sumsets(递推)

    Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 20315   Accepted: 7930 Descrip ...

  7. BZOJ2021: [Usaco2010 Jan]Cheese Towers

    2021: [Usaco2010 Jan]Cheese Towers Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 184  Solved: 107[Su ...

  8. P1759 通天之潜水(不详细,勿看)(动态规划递推,组合背包,洛谷)

    题目链接:点击进入 题目分析: 简单的组合背包模板题,但是递推的同时要刷新这种情况使用了哪些物品 ac代码: #include<bits/stdc++.h> using namespace ...

  9. P2347 砝码称重(动态规划递推,背包,洛谷)

    题目链接:P2347 砝码称重 参考题解:点击进入 纪念我第一道没理解题意的题 ''但不包括一个砝码也不用的情况'',这句话我看成了每个砝码起码放一个 然后就做不出来了 思路: 1.这题数据很小,10 ...

随机推荐

  1. jenkins+ant+jmeter实现自动化集成(详解)

    jenkins+ant+jmeter实现自动化集成 for window 一.jmeter 1.jmeter安装 二.ant 1.ant安装 三.ant运行 jmeter脚本 1.配置 四.jenki ...

  2. js下 Day10、尺寸位置属性

    一.元素尺寸信息 元素.offsetWidth: 元素的外宽高 width + padding + border 元素.offsetHeight: 元素的外宽高 height + padding + ...

  3. Java获取到异常信息进行保存(非Copy)

    吐槽:不知道从什么时候开始,各大博客网站的文章开始各种复制粘贴,想好好找一个解决方法,搜索出来的博客基本上千篇一律,主要是能解决问题也还行,还解决不了问题这就恶心了.... 所以被迫自己写一篇文章,然 ...

  4. Autofac官方文档翻译--一、注册组件--1注册概念

    官方文档:http://docs.autofac.org/en/latest/register/registration.html 一.注册概念 使用Autofac 注册组件,通过创建一个Contai ...

  5. 李宏毅机器学习课程笔记-2.5线性回归Python实战

    本文为作者学习李宏毅机器学习课程时参照样例完成homework1的记录. 任务描述(Task Description) 现在有某地空气质量的观测数据,请使用线性回归拟合数据,预测PM2.5. 数据集描 ...

  6. Prometheus从入门到精通:一、部署

    一.Prometheus是什么? prometheus是一个开源指标监控解决方案,指标就是指的CPU的使用率.内存使用率等数据. 二.Prometheus的架构 这里直接粘贴官网的架构图: 三.安装 ...

  7. (十五)、shell脚本之简单控制流结构

    一.基本的控制结构 1.控制流 常见的控制流就是if.then.else语句提供测试条件,测试条件可以基于各种条件.例如创建文件是否成功.是否有读写权限等,凡是执行的操作有失败的可能就可以用控制流,注 ...

  8. sh -s用法

    1.基本用法 (1)sh -s 会从标准输入中读取命令,并在子shell中执行 (2)sh -s 后从第一个非 - 开头的参数开始,依次被赋值给子shell的 $1,$2... (3)sh -s 的第 ...

  9. maven 导出所有依赖jar到指定路径

    mvn dependency:copy-dependencies -DoutputDirectory=lib

  10. 在onelogin中使用OpenId Connect Implicit Flow

    目录 简介 OpenId Implicit Flow 创建onelogin的配置 页面的运行和请求流程 关键代码 总结 简介 onelogin支持多种OpenId Connect的连接模式,上一篇文章 ...