zoukankan      html  css  js  c++  java
  • Business

    As the manager of your company, you have to carefully consider, for each project, the time taken to finish it, the deadline, and the profit you can gain, in order to decide if your group should take this project. For example, given 3 projects as the following:

    • Project[1] takes 3 days, it must be finished in 3 days in order to gain 6 units of profit.
    • Project[2] takes 2 days, it must be finished in 2 days in order to gain 3 units of profit.
    • Project[3] takes 1 day only, it must be finished in 3 days in order to gain 4 units of profit.

    You may take Project[1] to gain 6 units of profit. But if you take Project[2] first, then you will have 1 day left to complete Project[3] just in time, and hence gain 7 units of profit in total. Notice that once you decide to work on a project, you have to do it from beginning to the end without any interruption.

    Input Specification:

    Each input file contains one test case. For each case, the first line gives a positive integer N (≤), and then followed by N lines of projects, each contains three numbers P, L, and D where P is the profit, L the lasting days of the project, and D the deadline. It is guaranteed that L is never more than D, and all the numbers are non-negative integers.

    Output Specification:

    For each test case, output in a line the maximum profit you can gain.

    Sample Input:

    4
    7 1 3
    10 2 3
    6 1 2
    5 1 1
    
     

    Sample Output:

    18
     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 using namespace std;
     5 int dp[50][10000];
     6 struct node{
     7     int p,l,d;
     8 }a[55];
     9 int cmp(node a,node b){
    10     return a.d<b.d;    
    11 }
    12 int n;
    13 int imax(int a,int b){
    14     return a>b?a:b;
    15 }
    16 int main()
    17 {
    18     int i,j;
    19     int maxx=0;
    20     scanf("%d",&n);
    21     for(i=1;i<=n;i++){
    22         scanf("%d%d%d",&a[i].p,&a[i].l,&a[i].d);
    23         maxx=imax(maxx,a[i].d);
    24     }
    25     int maxn=0;
    26     sort(a+1,a+n+1,cmp);
    27     for(i=1;i<=n;i++)dp[i][a[i].l]=a[i].p;
    28     for(i=1;i<=n;i++){
    29         for(j=0;j<=maxx;j++){
    30             if(a[i].d>=j&&a[i].l<=j){
    31                 dp[i][j]=imax(dp[i-1][j-a[i].l]+a[i].p,dp[i-1][j]);
    32             }
    33             else if(a[i].d<j){
    34                 dp[i][j]=imax(dp[i-1][j],dp[i-1][a[i].d-a[i].l]+a[i].p);
    35             }
    36             else dp[i][j]=dp[i-1][j];
    37             maxn=imax(maxn,dp[i][j]);
    38         }
    39     }
    40    /* for(i=1;i<=n;i++){
    41         for(j=0;j<=maxx;j++){
    42             printf("%d %d:%d ",i,j,dp[i][j]);
    43             printf("
    ");
    44         }
    45     }*/
    46     printf("%d
    ",maxn);
    47     return 0;
    48 }
    诚者,君子之所守也。
  • 相关阅读:
    gerrit 修改前一次提交的方法(转载)
    数据结构实验之图论六:村村通公路 【克鲁斯卡尔算法】
    数据结构实验之图论五:从起始点到目标点的最短步数(BFS)
    数据结构实验之图论四:迷宫探索【dfs 求路径】
    Java 【打印俄文的英文字母】
    【留给自己的独白,长大了】
    Java 【 ArrayList应用 】 (SDUT 4069 C~K的班级)
    你的勇气去哪里了
    Java的 「 “ 结构体 ”」 与 「 “ 自定义排序 ” 」
    Java 中的 SimpleDateFormat 【 parse 和 format 】【转换时间格式】
  • 原文地址:https://www.cnblogs.com/SkystarX/p/12285825.html
Copyright © 2011-2022 走看看