bzoj 3824: [Usaco2014 Dec]Guard Mark【状压dp】
2024-08-30 19:30:16
设f[s]为已经从上到下叠了状态为s的牛的最大稳定度,转移的话枚举没有在集合里并且强壮度>=当前集合牛重量和的用min(f[s],当前放进去的牛还能承受多种)来更新,高度的话直接看是否有合法集合的高度达到要求即可
#include<iostream>
#include<cstdio>
using namespace std;
const int N=25;
int n,m,h[N],w[N],a[N],f[2000005],ans=-1;
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d%d%d",&h[i],&w[i],&a[i]);
for(int i=0,len=(1<<n)-1;i<=len;i++)
f[i]=-1;
f[0]=1e9;
for(int s=0,len=(1<<n)-1;s<=len;s++)
if(f[s]!=-1)
{
int we=0,he=0;
for(int i=1;i<=n;i++)
if(s&(1<<(i-1)))
we+=w[i],he+=h[i];//cerr<<s<<" "<<f[s]<<" "<<we<<" "<<he<<endl;
if(he>=m)
ans=max(ans,f[s]);
for(int i=1;i<=n;i++)
if(!(s&(1<<(i-1)))&&a[i]>=we)
f[s|(1<<(i-1))]=max(f[s|(1<<(i-1))],min(f[s],a[i]-we));
}
if(ans==-1)
puts("Mark is too tall");
else
printf("%d\n",ans);
return 0;
}
最新文章
- PHP中Exception异常
- psp记录个人项目花费时间
- select 触发事件
- Thinkpad 装 centos 7后发热量大处理
- 基于Bootstrap的jQuery开关按钮插件
- 学点儿c#语言wpf开发
- 自己搭建Wifi Pineapple Mark V
- 十天学会单片机Day1点亮数码管(数码管、外部中断、定时器中断)
- HDU 2571 命运 动态规划
- Windows Service 之 详解(一)
- Linux操作系统学习_用户态与内核态之切换过程
- 涉及模式之 装饰器模式详解(与IO不解的情缘)
- Android的ExpandableListView-android学习之旅(二十八)
- 免费申请使用IBM Cloud Lite(轻量套餐) 续
- Valgrind简介
- python 面向对象编程(高级篇)
- IOS Swift 训练
- 图片路径转base64字节码
- ios instancetype 和 id 的异同
- [转]Java 运算符的优先级
热门文章
- React学习之State
- uva 10604
- rror Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences ->; SQL Editor and reconnec
- HDOJ 5416 CRB and Tree DFS
- cef3的各个接口你知道几个
- DosBox 报错 this program requires dosxnt.exe to be in your path
- OSWorkFlow流程配置文件具体解释
- Android ListView异步载入图片乱序问题,原因分析及解决方式
- http协议的相关知识
- ubuntu hadoop伪分布式部署