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

    题目链接http://poj.org/problem?id=2392

    题目分类:动态规划

    代码

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #include<iostream>
    
    using namespace std;
    
    #define INF 0x3f3f3f3f
    int n;
    bool f[40010];
    int user[40010];
    
    struct P
    {
        int h,a,c;
    
    }goods[500];
    
    int cmp(P X,P Y)
    {
        return X.a<Y.a;
    }
    
    int main()
    {
       // freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        while(scanf("%d",&n)!=EOF)
        {
            memset(goods,0,sizeof(goods));
    
            for(int i=1;i<=n;i++)
            {
                scanf("%d %d %d",&goods[i].h,&goods[i].a,&goods[i].c);
            }
            sort(goods+1,goods+n+1,cmp);
            int maxx=0;
            memset(f,0,sizeof(f));
    
            f[0]=1;
            for(int i=1;i<=n;i++)
            {
                memset(user,0,sizeof(user));
                for(int j=goods[i].h;j<=goods[i].a;j++)
                {
                    if(!f[j] && f[j-goods[i].h] && user[j-goods[i].h]+1<=goods[i].c)
                    {
                        f[j]=1;
                        user[j]=user[j-goods[i].h]+1;
                       // printf("%d   %d   %d
    ",i,j,user[j]);
                        maxx=max(maxx,j);
                    }
                }
            }
            printf("%d
    ",maxx);
        }
        return 0;
    }
    
    /**
    printf("%d   %d   %d
    ",i,j,user[j]);
    1   5   1
    1   10   2
    1   15   3
    1   20   4
    2   7   1
    2   12   1
    2   14   2
    2   17   1
    2   19   2
    2   21   3
    2   22   1
    2   24   2
    2   26   3
    2   27   1
    2   29   2
    2   31   3
    2   34   2
    2   36   3
    3   2   1
    3   4   2
    3   6   3
    3   8   4
    3   9   1
    3   11   2
    3   13   3
    3   16   1
    3   18   2
    3   23   1
    3   25   2
    3   28   1
    3   30   2
    3   32   3
    3   33   1
    3   35   2
    3   37   3
    3   38   1
    3   39   4
    3   40   2
    3   41   5
    3   42   3
    3   43   6
    3   44   4
    3   46   5
    3   48   6
    48
    */
    anytime you feel the pain.hey,refrain.don't carry the world upon your shoulders
  • 相关阅读:
    SVG 支持动画
    js ==与===区别(两个等号与三个等号
    PHP设计模式之单例模式
    MySQL函数大全 及用法示例
    MySQL存储过程和函数
    MYSQl left join联合查询效率分析
    STL 算法[转 ]
    PHP 调整浏览器缓存
    php filter_var[转]
    C++ string学习[转]
  • 原文地址:https://www.cnblogs.com/gaoss/p/4947391.html
Copyright © 2011-2022 走看看