题目:https://www.luogu.org/problemnew/show/P3112
状压DP...转移不错。
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll const maxn=(<<),inf=1e18;
ll n,H,h[],w[],s[],f[maxn],mx,ans=-inf;
int main()
{
scanf("%lld%lld",&n,&H); mx=(<<n)-;
for(int i=;i<=n;i++)scanf("%lld%lld%lld",&h[i],&w[i],&s[i]);
f[]=inf;//下面取min
for(int i=;i<=mx;i++)
{
ll tmp=; f[i]=-inf;
for(int j=;j<=n;j++)
if((<<(j-))&i)
{
tmp+=h[j];
f[i]=max(f[i],min(f[i^(<<(j-))]-w[j],s[j]));
}
if(tmp>=H&&f[i]>)ans=max(ans,f[i]);
}
if(ans<)printf("Mark is too tall\n");
else printf("%lld\n",ans);
return ;
}