题意翻译

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. CentOS7 小技巧总结

    1.CentOS7 解决无法使用tab自动补全 原因:CentOS在最小化安装时,没有安装自动补全的包,需要手动安装. yum -y install bash-completion 安装好后,重新登陆 ...

  2. 小白专场-是否同一颗二叉搜索树-python语言实现

    目录 一.二叉搜索树的相同判断 二.问题引入 三.举例分析 四.方法探讨 4.1 中序遍历 4.2 层序遍历 4.3 先序遍历 4.4 后序遍历 五.总结 六.代码实现 一.二叉搜索树的相同判断 二叉 ...

  3. charles Web界面设置

    本文参考:charles Web界面设置 Web Inerface Web界面可以让您使用Web浏览器控制查询,您可以访问 http://control.charles 的Web界面,当查询运行时,您 ...

  4. Linux服务器MySQL安装

    Linux服务器MySQL安装 1. MySQL官网下载如图: 2. 安装MySQL [root@iZ2zebb0428roermd00462Z /]# rpm -ivh https://dev.my ...

  5. 59 (OC)* atomic是否绝对安全

    场景:如今项目中有这样一个场景,在一个自定义类型的Property在一个线程中改变的同时也要同时在另一个线程中使用它,使我不得不将Property定义成atomic,但是由此发现atomic并不会保证 ...

  6. php将图片存储在阿里云oss存储上

    创建两个方法 1.上传方法 use OSS\OssClient; use think\Config; use OSS\Core\OssException; /** * 存储文件 * * @param ...

  7. Django-中间件-csrf扩展请求伪造拦截中间件-Django Auth模块使用-效仿 django 中间件配置实现功能插拔式效果-09

    目录 昨日补充:将自己写的 login_auth 装饰装在 CBV 上 django 中间件 django 请求生命周期 ***** 默认中间件及其大概方法组成 中间件的执行顺序 自定义中间件探究不同 ...

  8. Redis 相关功能和实用命令(五)

    慢查询原因分析 由于 Redis 是单线程的,它内部维护了一个命令队列,所以当有耗时的命令出现时,比如 keys *,后面的命令会被阻塞,通查查出慢查询可以对服务进一步优化. 设置慢查询阀值:默认10 ...

  9. Flask基础(05)-->路由的基本定义

    # 导入Flask from flask import Flask # 创建Flask的应用程序 app = Flask(__name__) # http://127.0.0.1:5000/123或者 ...

  10. 正睿OI国庆DAY2:图论专题

    正睿OI国庆DAY2:图论专题 dfs/例题 判断无向图之间是否存在至少三条点不相交的简单路径 一个想法是最大流(后来说可以做,但是是多项式时间做法 旁边GavinZheng神仙在谈最小生成树 陈主力 ...