题意翻译

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. C#中using的使用-以FileStream写入文件为例

    场景 CS中FileStream的对比以及使用方法: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100396022 关注公众号 ...

  2. IO流——递归(输出所有文件)

    package pers.zbb.File; import java.io.File; public class FileDemo { public static void main(String[] ...

  3. H2 数据库使用简介

    博客地址:http://www.moonxy.com 一.前言 H2 是一个用 Java 开发的嵌入式数据库,它本身只是一个类库,即只有一个 jar 文件,可以直接嵌入到应用项目中.H2 主要有如下三 ...

  4. django 中namespace的问题

    在早期的django版本中 urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^polls/', include('polls.urls' ...

  5. Docker详解(三)

    目录 1. Docker镜像 1.1 镜像存储 1.2 base镜像 1.3 镜像Commit 2. Docker容器数据卷 2.1 基本介绍 2.2 数据卷 2.3 数据卷容器 序言:前两章我们主要 ...

  6. 暑期——第五周总结(Web连接hbase数据库)

    所花时间:7天 代码行:1000(python)+250(java) 博客量:1篇 了解到知识点 : 在尝试使用hbase当作数据库时,林子雨老师教程中有完整代码关于使用hbase,我就像当然认为只需 ...

  7. 代码审计之XSS及修复

    xss在平时的测试中,还是比较重要的,如果存在储存型xss,就可以做很多事情了,打cookie,添加管理员等等很多操作. 以下所有代码都是我自己写的,可能有不美观,代码错误等等问题,希望大家可以指正. ...

  8. Storm入门,看这篇就够了

    部分一:Srorm 简介 1.1 Storm是实时的数据流,Hadoop是批量离线数据 起源背景 Twitter 开源的一个类似于Hadoop的实时数据处理框架 Storm是由Nathan Marz ...

  9. 如何优雅的使用springboot项目内置tomcat

    问题:以前,我们在使用SSM框架的时候,都是通过外置的tomcat进行部署,如果想访问文件,直接拖到项目的根目录下面即可.假如我们需要放一个apk文件,然后让别人下载,只需将apk放到项目根目录下面, ...

  10. Flask基础(03)-->创建第一个Flask程序

    # 导入Flask from flask import Flask # 创建Flask的应用程序 # 参数__name__指的是Flask所对应的模块,其决定静态文件从哪个地方开始寻找 app = F ...