[Luogu3112] [USACO14DEC]后卫马克Guard Mark
题意翻译
FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark被N(2 <= N <= 20)头牛包围。牛们可以叠成一个牛塔,如果叠好后的高度大于或者等于Mark的高度,那牛们将抢到飞盘。
每头牛都一个身高,体重和耐力值三个指标。耐力指的是一头牛最大能承受的叠在他上方的牛的重量和。请计算牛们是否能够抢到飞盘。若是可以,请计算牛塔的最大稳定强度,稳定强度是指,在每头牛的耐力都可以承受的前提下,还能够在牛塔最上方添加的最大重量。
题目描述
Farmer John and his herd are playing frisbee. Bessie throws thefrisbee down the field, but it's going straight to Mark the field handon the other team! Mark has height H (1 <= H <= 1,000,000,000), butthere are N cows on Bessie's team gathered around Mark (2 <= N <= 20).They can only catch the frisbee if they can stack up to be at least ashigh as Mark. Each of the N cows has a height, weight, and strength.A cow's strength indicates the maximum amount of total weight of thecows that can be stacked above her.
Given these constraints, Bessie wants to know if it is possible forher team to build a tall enough stack to catch the frisbee, and if so,what is the maximum safety factor of such a stack. The safety factorof a stack is the amount of weight that can be added to the top of thestack without exceeding any cow's strength.
输入输出格式
输入格式:
INPUT: (file guard.in)
The first line of input contains N and H.
The next N lines of input each describe a cow, giving its
height,weight, and strength. All are positive integers at most 1
billion.
输出格式:
OUTPUT: (file guard.out)
If Bessie's team can build a stack tall enough to catch the frisbee,
please output the maximum achievable safety factor for such a stack.
Otherwise output "Mark is too tall" (without the quotes).
输入输出样例
2
设f[S]表示状态为S的最大稳定强度。
枚举i放在已选集合的最上方,显然f[s] = max(f[s']-w[i], s[i])。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <bitset>
#include <algorithm>
using namespace std;
#define int long long
inline int read() {
int res = ;char ch=getchar();
while(!isdigit(ch)) ch=getchar();
while(isdigit(ch)) res=(res<<)+(res<<)+(ch^), ch=getchar();
return res;
}
#define reg register int n, H;
struct date {
int h, w, s;
}p[];
int tot;
int f[<<], h[<<];
int bin[];
int ans = -; signed main()
{
bin[] = ; for(int i=;i<=;i++) bin[i] = bin[i-] << ;
n = read(), H = read();
for (reg int i = ; i <= n ; i ++)
{
p[i].h = read(), p[i].w = read(), p[i].s = read();
tot += p[i].h;
}
if (tot < H) return puts("Mark is too tall"), ;
memset(f, 0xcf, sizeof f);
f[] = ;
for (reg int S = ; S <= ( << n) - ; S ++)
for (reg int j = ; j <= n ; j ++)
if (S & bin[j-]) h[S] += p[j].h;
for (reg int S = ; S <= ( << n) - ; S ++)
{
for (reg int i = ; i <= n ; i ++)
{
if (S & bin[i-])
f[S] = max(f[S], min(f[S-bin[i-]] - p[i].w, p[i].s));
}
if (h[S] >= H) ans = max(ans, f[S]);
}
if (ans == -) return puts("Mark is too tall"), ;
printf("%lld\n", ans);
return ;
}
[Luogu3112] [USACO14DEC]后卫马克Guard Mark的更多相关文章
- 洛谷 P3112 [USACO14DEC]后卫马克Guard Mark
题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...
- 洛谷P3112 [USACO14DEC]后卫马克Guard Mark
题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...
- LUOGU P3112 [USACO14DEC]后卫马克Guard Mark
题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...
- [USACO14DEC]后卫马克Guard Mark
题目描述 FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark 被N(2 <= N <= 20)头牛包围.牛们可以叠成一个牛塔,如果 ...
- 洛谷 3112 [USACO14DEC]后卫马克Guard Mark——状压dp
题目:https://www.luogu.org/problemnew/show/P3112 状压dp.发现只需要记录当前状态的牛中剩余承重最小的值. #include<iostream> ...
- 洛谷 P3112 后卫马克Guard Mark
->题目链接 题解: 贪心+模拟 #include<algorithm> #include<iostream> #include<cstring> #incl ...
- bzoj 3824: [Usaco2014 Dec]Guard Mark【状压dp】
设f[s]为已经从上到下叠了状态为s的牛的最大稳定度,转移的话枚举没有在集合里并且强壮度>=当前集合牛重量和的用min(f[s],当前放进去的牛还能承受多种)来更新,高度的话直接看是否有合法集合 ...
- 洛谷 P3112 后卫马克 —— 状压DP
题目:https://www.luogu.org/problemnew/show/P3112 状压DP...转移不错. 代码如下: #include<iostream> #include& ...
- 剑指offer 练习题目
#include <iostream> #include<vector> #include <stack> #include<map> #include ...
随机推荐
- C#中using的使用-以FileStream写入文件为例
场景 CS中FileStream的对比以及使用方法: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100396022 关注公众号 ...
- Python中使用pip安装库时提示:远程主机强迫关闭了一个现有的连接
场景 在cmd中使用pip install moviepy时,需要安装一些依赖库,很长时间后提示: 远程主机中断了一个现有的连接. 原因是默认镜像源下载过慢,将其修改为国内或者设置安装时的源. 这里以 ...
- 遇到XML-GB2312网页编码的处理方法
报的错误:encoding error : input conversion failed due to input error, bytes I/O error : encoder error 1 ...
- [PySpark] 01 - Preview parquet files in S3 ×××
本系列基于实际测试数据,质量保证,不自欺欺人. 实践是检验真理的唯一标准. Swipejobs is all about matching Jobs to Workers. Your challeng ...
- Python3.7.4入门-0/1To Begin/数据类型与结构
0 To Begin //:向下取整除法 **:乘方 在交互模式下,上一次打印出来的表达式被赋值给变量 _ 如果不希望前置了 \ 的字符转义成特殊字符,可以使用 原始字符串 方式,在引号前添加 r 即 ...
- Audio Bit Depth Super-Resolution with Neural Networks
Audio Bit Depth Super-Resolution with Neural Networks 作者:Thomas Liu.Taylor Lundy.William Qi 摘要 Audio ...
- 自己动手实现智能家居之树莓派GPIO简介(Python版)
[前言] 一个热爱技术的人一定向往有一个科技感十足的环境吧,那何不亲自实践一下属于技术人的座右铭:“技术改变世界”. 就让我们一步步动手搭建一个属于自己的“智能家居平台”吧(不要对这个名词抬杠啦,技术 ...
- 使用Docker安装FastDFS(分布式文件系统)
1. 获取镜像 可以利用已有的FastDFS Docker镜像来运行FastDFS. 获取镜像可以通过下载 docker image pull delron/fastdfs 也可是直接使用提前下载的镜 ...
- 并发编程之多线程(Java)
一.线程与进程区别 每个正在系统上运行的程序都是一个进程.每个进程包含一到多个线程.线程是一组指令的集合,或者是程序的特殊段,它可以在程序里独立执行.也可以把它理解为代码运行的上下文.所以线程基本上是 ...
- 【windows】远程桌面 把远程服务器的explorer.exe进程关掉了,咋办?
在操作windows2008R2服务器时不小心把explorer.exe进程关闭了,瞬间整个界面就蓝色了. 重启,做不到,各种快捷键用不了,最后发现Alt+Tab可以用,刚好打开了IIS, 打开其中一 ...