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 }
    诚者,君子之所守也。
  • 相关阅读:
    [题解]北京2018
    [数据结构][字典树]Word Puzzles
    [数据结构][字典树]Hardwood Species
    [数学][广义欧拉定理]上帝与集合的正确用法
    Equal Sums
    Useful Decomposition
    网络流 EK算法
    线段树各类操作
    唯一分解定理
    Kuro and Walking Route
  • 原文地址:https://www.cnblogs.com/SkystarX/p/12285825.html
Copyright © 2011-2022 走看看