zoukankan      html  css  js  c++  java
  • POJ 2392 Space Elevator

    排序+背包。

    先对按高度限制从小到大排序,然后做背包即可。0/1背包300多ms过的,可以用完全背包二进制优化。

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    
    const int maxn=400+10;
    int n;
    struct X
    {
        int h,c,a;
    }s[maxn];
    int dp[400000+10];
    int ans;
    
    bool cmp(const X&a,const X&b)
    {
        return a.a<b.a;
    }
    void read()
    {
        for(int i=1;i<=n;i++)
            scanf("%d%d%d",&s[i].h,&s[i].a,&s[i].c);
        sort(s+1,s+1+n,cmp);
    }
    
    void init()
    {
        memset(dp,0,sizeof dp); dp[0]=1;
        ans=0;
    }
    
    void work()
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=s[i].c;j++)
            {
                for(int p=s[i].a;p>=s[i].h;p--)
                {
                    if(dp[p-s[i].h]==1)
                    {
                        dp[p]=1;
                        ans=max(ans,p);
                    }
                }
            }
        }
        printf("%d
    ",ans);
    }
    
    int main()
    {
        while(~scanf("%d",&n))
        {
            read();
            init();
            work();
        }
        return 0;
    }
  • 相关阅读:
    jTopo——js库
    node.js
    php 入门笔记
    D3 入门笔记
    webpack笔记
    React.js
    Grunt等前端自动化构建工具
    vue3.0的新特性
    electron-builder 打包流程
    vue里面如何下载图片,如何下载文件
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5308328.html
Copyright © 2011-2022 走看看