• HDU 4502 吉哥系列故事——临时工计划


    吉哥系列故事——临时工计划

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 2357    Accepted Submission(s): 887

    Problem Description
      俗话说一分钱难倒英雄汉,高中几年下来,吉哥已经深深明白了这个道理,因此,新年开始存储一年的个人资金已经成了习惯,不过自从大学之后他不好意思再向大人要压岁钱了,只能把唯一的希望放到自己身上。可是由于时间段的特殊性和自己能力的因素,只能找到些零零碎碎的工作,吉哥想知道怎么安排自己的假期才能获得最多的工资。   已知吉哥一共有m天的假期,每天的编号从1到m,一共有n份可以做的工作,每份工作都知道起始时间s,终止时间e和对应的工资c,每份工作的起始和终止时间以天为单位(即天数编号),每份工作必须从起始时间做到终止时间才能得到总工资c,且不能存在时间重叠的工作。比如,第1天起始第2天结束的工作不能和第2天起始,第4天结束的工作一起被选定,因为第2天吉哥只能在一个地方工作。   现在,吉哥想知道怎么安排才能在假期的m天内获得最大的工资数(第m+1天吉哥必须返回学校,m天以后起始或终止的工作是不能完成的)。
     
    Input
    第一行是数据的组数T;每组数据的第一行是2个正整数:假期时间m和可做的工作数n;接下来n行分别有3个正整数描述对应的n个工作的起始时间s,终止时间e,总工资c。
    [Technical Specification] 1<=T<=1000 9<m<=100 0<n<=1000 s<=100, e<=100, s<=e c<=10000
     
    Output
    对于每组数据,输出吉哥可获得的最高工资数。
     
    Sample Input
    1 10 5 1 5 100 3 10 10 5 10 100 1 4 2 6 12 266
     
    Sample Output
    102
     
    Source
     
    Recommend
    liuyiding
     
    思路:
    简单的DP
     
    代码:
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <cstdlib>
    #include <algorithm>
    using namespace std;
    int
    t,m,n;
    int
    dp[1010];
    int
    map[1010][3];
    int
    mapf[110];
    int
    min(int x,int y)
    {

        if
    (x > y)
           return
    y;
        return
    x;
    }

    bool
    maax(int x,int y)
    {

        if
    (x > y)
           return
    1;
        return
    0;
    }

    int
    max(int x,int y)
    {

        if
    (x > y)
           return
    x;
        return
    y;
    }

    int
    main()
    {

        scanf("%d",&t);
        while
    (t --)
        {

            scanf("%d%d",&m,&n);
            memset(dp,0,sizeof(dp));
            for
    (int i = 1;i <= n;i ++)
               scanf("%d%d%d",&map[i][0],&map[i][1],&map[i][2]);
            int
    hau1,hau2,hau3;
            for
    (int g = 1;g <= n;g ++)
                for
    (int h = g;h <= n;h ++)
                    if
    (maax(map[g][1],map[h][1]) ||
                    (
    map[g][1] == map[h][1] && map[g][0] > map[h][0])) 
                    {

                     hau1 = map[h][0];map[h][0] = map[g][0];map[g][0] = hau1;
                     hau2 = map[h][1];map[h][1] = map[g][1];map[g][1] = hau2;
                     hau3 = map[h][2];map[h][2] = map[g][2];map[g][2] = hau3;
                    }

            //for(int i = 1;i <= n;i ++)
                //printf("%d %d %d ",map[i][0],map[i][1],map[i][2]);
            for(int l = 1;l <= n; l ++)
                 for
    (int r = 1;r <= m;r ++)
                {

                   if
    (map[l][1] > r)
                      continue
    ;
                   dp[r] = max(dp[r],dp[map[l][0] - 1] + map[l][2]);
                }

            printf("%d ",dp[m]);
        }
    }
     
  • 相关阅读:
    Shodan在渗透测试及漏洞挖掘中的一些用法
    QUdpSocket 简单用法
    用QT操作数据库(本周学的)
    Qt使用UDp通信、套接字socket的成员函数bind()的作用
    ppm的含义
    数字的补数
    两数之和
    C++中的最大整数最小整数
    如何使用dockerfile将jar包生成镜像
    python3解决 json.dumps中文乱码
  • 原文地址:https://www.cnblogs.com/GODLIKEING/p/3282626.html
Copyright © 2020-2023  润新知