设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;
}

最新文章

  1. PHP中Exception异常
  2. psp记录个人项目花费时间
  3. select 触发事件
  4. Thinkpad 装 centos 7后发热量大处理
  5. 基于Bootstrap的jQuery开关按钮插件
  6. 学点儿c#语言wpf开发
  7. 自己搭建Wifi Pineapple Mark V
  8. 十天学会单片机Day1点亮数码管(数码管、外部中断、定时器中断)
  9. HDU 2571 命运 动态规划
  10. Windows Service 之 详解(一)
  11. Linux操作系统学习_用户态与内核态之切换过程
  12. 涉及模式之 装饰器模式详解(与IO不解的情缘)
  13. Android的ExpandableListView-android学习之旅(二十八)
  14. 免费申请使用IBM Cloud Lite(轻量套餐) 续
  15. Valgrind简介
  16. python 面向对象编程(高级篇)
  17. IOS Swift 训练
  18. 图片路径转base64字节码
  19. ios instancetype 和 id 的异同
  20. [转]Java 运算符的优先级

热门文章

  1. React学习之State
  2. uva 10604
  3. 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 -&gt; SQL Editor and reconnec
  4. HDOJ 5416 CRB and Tree DFS
  5. cef3的各个接口你知道几个
  6. DosBox 报错 this program requires dosxnt.exe to be in your path
  7. OSWorkFlow流程配置文件具体解释
  8. Android ListView异步载入图片乱序问题,原因分析及解决方式
  9. http协议的相关知识
  10. ubuntu hadoop伪分布式部署