题目描述

Farmer John and his herd are playing frisbee. Bessie throws the

frisbee down the field, but it's going straight to Mark the field hand

on the other team! Mark has height H (1 <= H <= 1,000,000,000), but

there 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 as

high 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 the

cows that can be stacked above her.

Given these constraints, Bessie wants to know if it is possible for

her 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 factor

of a stack is the amount of weight that can be added to the top of the

stack without exceeding any cow's strength.

FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark

被N(2 <= N <= 20)头牛包围。牛们可以叠成一个牛塔,如果叠好后的高度大于或者等于Mark的高度,那牛们将抢到飞盘。

每头牛都一个身高,体重和耐力值三个指标。耐力指的是一头牛最大能承受的叠在他上方的牛的重量和。请计算牛们是否能够抢到飞盘。若是可以,请计算牛塔的最大稳定强度,稳定强度是指,在每头牛的耐力都可以承受的前提下,还能够在牛塔最上方添加的最大重量。

输入输出格式

输入格式:

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 

动规 状压DP

看到数据范围就是状压DP了吧233

有那么一阵子我有DFS可以剪枝强行卡过去的错觉,然而果然是错觉。

f[i]记录的是当前状态(状压当前有哪些牛)的最大安全因子是多大

 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int INF=0x3f3f3f3f;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
int f[<<];
int g[<<];
struct node{
int h,w,s;
}a[mxn];
int n,H;
int ans=-;
int main(){
int i,j;
n=read();H=read();int smm=;
for(i=;i<n;i++){
a[i].h=read();a[i].w=read();a[i].s=read();
smm+=a[i].h;
}
if(smm<H){printf("Mark is too tall\n");return ;}
memset(f,-,sizeof f);
f[]=INF;
int ed=(<<n)-;
for(i=;i<=ed;i++){
for(j=;j<n;j++){
if((i>>j)&)continue;
int v=i^(<<j);
if(f[i]<a[j].w)continue;
int t=min(f[i]-a[j].w,a[j].s);
f[v]=max(f[v],t);
g[v]=g[i]+a[j].h;//累计高度
if(v && g[v]>=H)ans=max(ans,f[v]);
}
}
if(ans==-)printf("Mark is too tall\n");
else printf("%d\n",ans);
return ;
}

洛谷P3112 [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. 洛谷 3112 [USACO14DEC]后卫马克Guard Mark——状压dp

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

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

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

  4. [Luogu3112] [USACO14DEC]后卫马克Guard Mark

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

  5. [USACO14DEC]后卫马克Guard Mark

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

  6. 洛谷 P3112 后卫马克Guard Mark

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

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

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

  8. 洛谷P3110 [USACO14DEC]驮运Piggy Back

    P3110 [USACO14DEC]驮运Piggy Back 题目描述 贝西和她的妹妹艾尔斯白天在不同的地方吃草,而在晚上他们都想回到谷仓休息.聪明的牛仔,他们想出了一个计划,以尽量减少他们在步行时花 ...

  9. 洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver

    P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题目描述 The cows are out exercising their hooves again! There are N ...

随机推荐

  1. Python元组,列表,字典,集合

    1.元组 元组是有序的,只有index和count两种方法,一看到元组,就提醒是不可更改的 names = ('wll', 'ly', 'jxx', 'syq') (1)index方法 print(n ...

  2. ubuntu安装wine 和sourceinsght

    ubuntu安装wine: 1.sudo apt-get update 2.sudo apt-get install wine 安装完成后会在当前用户目录的的家目录下生成.wine目录,该目录就是wi ...

  3. POJ 2676 数独(DFS)

    Sudoku Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 21612   Accepted: 10274   Specia ...

  4. 笔记-reactor pattern

    笔记-reactor pattern 1.      reactor模式 1.1.    什么是reactor模式 The reactor design pattern is an event han ...

  5. Trident整合MongoDB

    MongoDB是大数据技术中常用的NoSql型数据库,它提供的大量的查询.聚合等操作函数,对于大量查询的日志系统来说,该MongoDB是大数据日志存储的福音.Storm的高级编程技术Trident,也 ...

  6. springmvc上传图片并显示--支持多图片上传

    实现上传图片功能在Springmvc中很好实现.现在我将会展现完整例子. 开始需要在pom.xml加入几个jar,分别是: <dependency> <groupId>comm ...

  7. BAD_ACCESS在什么情况下出现?如何调试BAD_ACCESS错误

    1. 访问一个僵尸对象,访问僵尸对象的成员变量或者向其发消息 死循环 2. 设置全局断点快速定位问题代码所在行 开启僵尸对象调试功能  

  8. Redmine部署到Windows Azure

    有幸,今天可以尝试将Redmine部署到Windows Azure中,记下点滴,方便大家查阅 步骤一:Windows Azure中安装Ubuntu VM 遇到的问题,创建VM时会提示云服务.云存储订阅 ...

  9. 剑指Offer - 九度1389 - 变态跳台阶

    剑指Offer - 九度1389 - 变态跳台阶2013-11-24 04:20 题目描述: 一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级.求该青蛙跳上一个n级的台阶总共有多少种跳 ...

  10. 抓包工具 - Fiddler - (三)

    <转载自 miantest> 我们知道Fiddler是位于客户端和服务器之间的代理,它能够记录客户端和服务器之间的所有 HTTP请求,可以针对特定的HTTP请求,分析请求数据.设置断点.调 ...