zoukankan      html  css  js  c++  java
  • luogu P4823 [TJOI2013]拯救小矮人

    题解 传送门

    对于每个小矮人,一旦他出去浪,就再也回不来了
    所以肯定要让不容易出去的,先出去浪
    关爱老幼病残孕及带小孩的乘客
    所以我们按小矮人的身高+手长排遍序
    因为长得高的贡献可能更大
    而手长的更容易出去
    .
    .
    .
    排完序后
    直接跑遍背包,求出走掉i个小矮人所剩余的最大高度

    代码

    #include<bits/stdc++.h>
    using namespace std;
    #define re register
    #define ll long long
    #define db double
    #define in inline
    #define get getchar()
    in int read()
    {
    	int t=0,x=1; char ch=get;
    	while ((ch<'0' || ch>'9') && ch!='-') ch=get;
    	if(ch=='-') ch=get,x=-1;
    	while (ch<='9' && ch>='0') t=t*10+ch-'0', ch=get;
    	return t*x;
    }
    const int _=2010;
    struct human{
    	int a,b,s;
    }p[_]; //小矮人(为啥是human???)
    int n,h,f[_];
    
    in int cmp(human a,human b){return a.s<b.s;}
    
    int main()
    {
    	n=read();
    	memset(f,-1,sizeof(f));f[0]=0;
    	for(re int i=1;i<=n;i++)
    	{
    		p[i].a=read(),p[i].b=read();
    		p[i].s=p[i].a+p[i].b,f[0]+=p[i].a;
    	}
    	h=read();
    	sort(p+1,p+n+1,cmp);
    	int ans=0;
    	for(re int i=1;i<=n;i++)
    	{
    		for(re int j=ans;j>=0;j--)
    		{
    			if(p[i].b+f[j]>=h)f[j+1]=max(f[j+1],f[j]-p[i].a);
    			if(f[ans+1]>=0)ans++;
    		}
    	}
    	cout<<ans<<endl;
    	return 0;
    }
    
    
    嗯,就这样了...
  • 相关阅读:
    正睿提高组2017模拟题三T1
    数位dp【转载】
    正睿提高组2017模拟题二T2
    【树状数组二维区间加+区间查询模板】bzoj3132
    【树状数组区间加+区间查询模板】洛谷P3372
    51Nod
    CodeForces 631E Product Sum
    CodeForces
    [不知道哪来的题] 完美理论
    CodeForces
  • 原文地址:https://www.cnblogs.com/yzhx/p/10655883.html
Copyright © 2011-2022 走看看