[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 ...
随机推荐
- 装系统 ------ 使用微PE 做系统盘
1.什么是PE系统 pe系统是一种装系统的系统,也就是预装系统的系统,它是一种系统预装环境和工具. 可以放在U盘或光盘里随身携带,可以用来给电脑装系统 2.常见的制作pe 系统的工具 大白菜,U启动, ...
- 使用Bookinfo应用测试Kuma服务网格
最近,开源API管理平台Kong服务供应商近日放出了新的开源项目Kuma.本文尝试将 bookinfo 应用部署在 Kuma 网格中,以便帮助大家更好的理解 Kuma 项目. Kuma是能用于管理 ...
- 搭建maven本地仓库,idea应用本地maven仓库
提环境: 安装好tomcat.maven.jdk.idea. 打开maven安装目录,在目录下新建 maven仓库文件夹(名子随便): 打开conf\setting.xml 加入<localRe ...
- 一篇文章了解Redis数据库
文章原创于公众号:程序猿周先森.本平台不定时更新,喜欢我的文章,欢迎关注我的微信公众号. redis是一个key-value存储系统.它支持存储的value类型相对更多,包括string(字符串).l ...
- Spring Cloud Gateway 之请求坑位[微服务IP不同请求会失败]
问题产生背景 在使用Spring Cloud Gateway过程中,希望配置多Routes映射不同的微服务,因为Gateway 和Zuul的访问路径不同(zuul 会带有服务service Id),造 ...
- 转:LinkedHashMap和HashMap的比较使用
import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.uti ...
- 第六届蓝桥杯java b组第8题
乐羊羊饮料厂正在举办一次促销优惠活动.乐羊羊C型饮料,凭3个瓶盖可以再换一瓶C型饮料,并且可以一直循环下去,但不允许赊账. 请你计算一下,如果小明不浪费瓶盖,尽量地参加活动,那么,对于他初始买入的n瓶 ...
- embedding技术
目录 word2vec 负采样 目标函数 反向梯度 层次softmax NPLM的目标函数和反向梯度 目标函数 反向梯度 GNN(图神经网络) deepwalk node2vec 附录 word2ve ...
- 为什么不使用SOAP进行点对点联系,而使用ESB呢
图片截至: https://www.zhihu.com/question/29475224
- Java 文章链接
Java表单验证封装类 https://www.cnblogs.com/linjiqin/archive/2013/11/18/3429424.html 微信企业号接入JDK6和JDK7及JDK8加解 ...