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 }
    诚者,君子之所守也。
  • 相关阅读:
    手机微信浏览器手动清楚浏览器缓存
    CSS 图像精灵怎么用(css sprites定位技术) 图标定位
    电商平台应该分析哪些数据?具体怎么去分析?
    酷家乐装修方案
    字体识别(根据图片截图识别字体) 求字体
    酿造系列:自己酿造夏日饮用的低度甜酒好喝吗?如何酿造?
    xcode Xcode_9.2.xip 官方离线下载地址
    nginx给server增加日志配置
    用monit监控mongodb,崩溃后自动重启mongdb
    电商产品经理进阶一:电商基础流程
  • 原文地址:https://www.cnblogs.com/SkystarX/p/12285825.html
Copyright © 2011-2022 走看看