洛谷P3112 [USACO14DEC]后卫马克Guard Mark
题目描述
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).
输入输出样例
4 10
9 4 1
3 3 5
5 5 10
4 4 5
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的更多相关文章
- 洛谷 P3112 [USACO14DEC]后卫马克Guard Mark
题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...
- 洛谷 3112 [USACO14DEC]后卫马克Guard Mark——状压dp
题目:https://www.luogu.org/problemnew/show/P3112 状压dp.发现只需要记录当前状态的牛中剩余承重最小的值. #include<iostream> ...
- LUOGU P3112 [USACO14DEC]后卫马克Guard Mark
题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...
- [Luogu3112] [USACO14DEC]后卫马克Guard Mark
题意翻译 FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark被N(2 <= N <= 20)头牛包围.牛们可以叠成一个牛塔,如果叠 ...
- [USACO14DEC]后卫马克Guard Mark
题目描述 FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark 被N(2 <= N <= 20)头牛包围.牛们可以叠成一个牛塔,如果 ...
- 洛谷 P3112 后卫马克Guard Mark
->题目链接 题解: 贪心+模拟 #include<algorithm> #include<iostream> #include<cstring> #incl ...
- 洛谷 P3112 后卫马克 —— 状压DP
题目:https://www.luogu.org/problemnew/show/P3112 状压DP...转移不错. 代码如下: #include<iostream> #include& ...
- 洛谷P3110 [USACO14DEC]驮运Piggy Back
P3110 [USACO14DEC]驮运Piggy Back 题目描述 贝西和她的妹妹艾尔斯白天在不同的地方吃草,而在晚上他们都想回到谷仓休息.聪明的牛仔,他们想出了一个计划,以尽量减少他们在步行时花 ...
- 洛谷 P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver
P3111 [USACO14DEC]牛慢跑Cow Jog_Sliver 题目描述 The cows are out exercising their hooves again! There are N ...
随机推荐
- python爬虫-简单使用xpath下载图片
首先 1.为方便以下进行 谷歌浏览器里要安装xpath脚本 2.下载一个lmxl 命令:pip install lxml 3. 以下三张图是一个,当时爬的 <糗事百科>里的图片 值 ...
- linux通用GPIO驱动,写GPIO文件不立即生效问题解决
Linux开发平台实现了通用GPIO的驱动,用户通过,SHell或者系统调用能控制GPIO的输出和读取其输入值.其属性文件均在/sys/class/gpio/目录下,该目录下有export和unexp ...
- Black Box POJ1442
Description Our Black Box represents a primitive database. It can save an integer array and has a sp ...
- python-10多进程
1-多进程(multiprocessing), 1个父进程可以有多少子进程 1.1下面的例子演示了启动一个子进程并等待其结束 from multiprocessing import Process i ...
- WCF入门一[WCF概述]
一.什么是WCF WCF是使用托管代码建立和运行面向服务(Service Oriented)应用程序的统一框架.它使得开发者能够建立一个跨平台的.安全.可信赖.事务性的解决方案,且能与已有系统兼容协作 ...
- JavaScript 仿ios滑动选择器
从git上找了一个,不过不是我想要的,更改了许多.到了我想要的效果: roller_selector_0_9.js 首先上js: "use strict"; /* * Author ...
- 单例解决存储微信Token信息保留两小时
采用单例模式可以存储初始化数据,比如第一次对/api/test接口进行了访问,传入的信息为“123”,则在两个小时之内返回的信息依然是“123”,无论传入的参数是什么,如果有效时间过了两个小时,比如传 ...
- laravel5.5路由使用name的好处
使用name的好处 辅助函数 route 可以用于为指定路由生成 URL.命名路由生成的 URL 不与路由上定义的 URL 相耦合.因此,就算路由的 URL 有任何更改,都不需要对 route 函数调 ...
- DataGridView重查后,返回原来所在行
首先记录选中行 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 //查询前记录选中行 int _currentRow = 0; //int _cu ...
- Windows下安装jenkins,关闭jenkins,修改jenkins端口号
1.Jenkins安装部署 在官网下载Jenkins: https://jenkins.io/download/thank-you-downloading-windows-installer-stab ...