题意翻译

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).

输入输出样例

输入样例#1:
复制

4 10
9 4 1
3 3 5
5 5 10
4 4 5
输出样例#1: 复制

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的更多相关文章

  1. 洛谷 P3112 [USACO14DEC]后卫马克Guard Mark

    题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...

  2. 洛谷P3112 [USACO14DEC]后卫马克Guard Mark

    题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...

  3. LUOGU P3112 [USACO14DEC]后卫马克Guard Mark

    题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...

  4. [USACO14DEC]后卫马克Guard Mark

    题目描述 FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark 被N(2 <= N <= 20)头牛包围.牛们可以叠成一个牛塔,如果 ...

  5. 洛谷 3112 [USACO14DEC]后卫马克Guard Mark——状压dp

    题目:https://www.luogu.org/problemnew/show/P3112 状压dp.发现只需要记录当前状态的牛中剩余承重最小的值. #include<iostream> ...

  6. 洛谷 P3112 后卫马克Guard Mark

    ->题目链接 题解: 贪心+模拟 #include<algorithm> #include<iostream> #include<cstring> #incl ...

  7. bzoj 3824: [Usaco2014 Dec]Guard Mark【状压dp】

    设f[s]为已经从上到下叠了状态为s的牛的最大稳定度,转移的话枚举没有在集合里并且强壮度>=当前集合牛重量和的用min(f[s],当前放进去的牛还能承受多种)来更新,高度的话直接看是否有合法集合 ...

  8. 洛谷 P3112 后卫马克 —— 状压DP

    题目:https://www.luogu.org/problemnew/show/P3112 状压DP...转移不错. 代码如下: #include<iostream> #include& ...

  9. 剑指offer 练习题目

    #include <iostream> #include<vector> #include <stack> #include<map> #include ...

随机推荐

  1. valueForKey与valueForKeyPath 区别

    1.删除数组中重复的数据 2.valueForKeyPath:可以深层次取到子属性,不管隐藏的多深  valueForKey:无法取到深层次子属性 但是也有其相似的地方: 比如:快速找到字典数组中ke ...

  2. 使用 Nginx 部署前后端分离项目,解决跨域问题

    前后端分离这个问题其实松哥和大家聊过很多了,上周松哥把自己的两个开源项目部署在服务器上以帮助大家可以快速在线预览(喜大普奔,两个开源的 Spring Boot + Vue 前后端分离项目可以在线体验了 ...

  3. SpringBoot + Jpa(Hibernate) 架构基本配置

    1.基于springboot-1.4.0.RELEASE版本测试 2.springBoot + Hibernate + Druid + Mysql + servlet(jsp) 一.maven的pom ...

  4. [LeetCode] 面试题之犄角旮旯 第叁章

    题库:LeetCode题库 - 中等难度 习题:网友收集 - zhizhiyu 此处应为一个简单的核心总结,以及练习笔记. 查找一个数“在不在”?桶排序理论上貌似不错. 回文问题 ----> [ ...

  5. DOM之节点操作

    DOM提供了很多实用的API,这些API让我们可以轻松的访问HTML文档.所谓API(应用程序接口),简单来说,就是让我们可以直接使用它访问程序的一些属性或方法,而不用了解程序内部的运作过程和原理. ...

  6. MySQL中对字段内容为Null的处理

    使用如下指令,意思就是 select IFNULL(jxjy,0) AS jxjy from yourTable ifnull(a,b) 意思是指:如果字段a为null,就等于b if( sex = ...

  7. jenkins上下游工程以及空间占用处理

    1.最近项目架构调整,把十几个java项目整合为一个大的项目,这样构建上游工程成功后下游工程会自动构建 解决如下:取消这个勾选即可 2.构建单个项目时,会把所有子工程都打包一次 解决如下:指定构建时的 ...

  8. docker运行jexus+mono爬坑记

    新的.net core都已经支持docker.手头有一些原来开发的asp.net旧项目,用的asp.net mvc开发的,跑在.net formwork 4.6上. 在docker的公共仓库searc ...

  9. CDH集群的配置优化须知

           通过改善IFile阅读器的性能 IFile Reader,进而可改善随机处理程序并减少储备空间,达到MapReduce的配置最佳实践要求.而MapReduce shuffle的处理程序和 ...

  10. 每个人都要学的图片压缩终极奥义,有效解决 Android 程序 OOM

    # 由来 在我们编写 Android 程序的时候,几乎永远逃避不了图片压缩的难题.除了应用图标之外,我们所要显示的图片基本上只有两个来源: 来自网络下载 本地相册中加载 不管是网上下载下来的也好,还是 ...