Nine degrees OJ topic 1499: Project arrangement

Source: Internet
Author: User
Tags ming

Title Description:

Xiao Ming is doing projects in the open source community every day, assuming that he has a lot of projects to choose from every day, and that each project has a start time and deadlines, assuming that after each project, getting paid is different. Because Xiao Ming will soon master graduate, facing to buy a house, buy a car, give his girlfriend to buy all kinds of bags of pear, but his wallet is empty, he needs enough money to enrich the wallet. Omnipotent netizens trouble you to help Xiao Ming, how to arrange their own projects in the shortest possible time to ensure the most money (note: When doing projects, the project can not be parallel, that is, two projects can not overlap between the time, but a project just ended, you can immediately do another project, that is, the project start and end point can overlap).

Input:

The input may contain multiple test samples.
For each test case, the first line of input is an integer n (1<=n<=10000): The number of items that represent Xiaoming's hands.
Then there are n rows, each with 3 integers st, Ed, and Val, each representing the start of the project, the deadline and the project remuneration, separated by a space between the two adjacent numbers.
The values for St, Ed, and value are all within the range of 32-bit signed integers (int), and the input data guarantees that the sum of the value of all data is also within the range of int.

Output:

For each test case, output the maximum reward that xiaoming can get.

Sample input:
31 3 64 8 92 5 1641 14 105 20 1515 20 818 22 12
Sample output:
1622

This problem is done with dynamic programming, starting with the dp[], the array is labeled as time, but it takes a long, an exemplary code as follows
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <algorithm>5 #defineMAX 100026 #defineINF 999999997 structProject8 {9     intstart;Ten     intend; One     intvalue; A }; -  - intcmpConst void*a,Const void*b) { theProject at = * (Project *) A; -Project BT = * (Project *) b; -     returnAt.end-Bt.end; - } +  - Project Act[max]; + intDp[inf]; A  at intMainintargcChar Const*argv[]) - { -     intN; -     //freopen ("Input.txt", "R", stdin); -      while(SCANF ("%d", &n)! =EOF) { -         intEndmax =0; in          for(inti =0; I < n; i++) { -scanf" %d%d%d", &act[i].start, &act[i].end, &act[i].value); to             if(Act[i].end >Endmax) { +Endmax =Act[i].end; -             } the         } *         //qsort (act,n,sizeof (Project), CMP); $         Panax NotoginsengMemset (DP,0,sizeof(DP)); -          for(inti =0; I < n; i++) { the              for(intj = Endmax; J >= Act[i].end; j--) { +                 inttemp = Dp[act[i].start] +Act[i].value; A                 if(Dp[j] <temp) { theDP[J] =temp; +                 } -             } $         } $printf"%d\n", Dp[endmax]); -     } -     return 0; the}

Then the meaning of the subscript is changed to the task number, the code is as follows

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <algorithm>5#include <iostream>6 #defineMAX 100027 8 using namespacestd;9 structProjectTen { One     intstart; A     intend; -     intvalue; - }; the  - intcmpConst void*a,Const void*b) { -Project at = * (Project *) A; -Project BT = * (Project *) b; +     returnAt.end-Bt.end; - } +  A Project Act[max]; at intDp[max]; -  - intMainintargcChar Const*argv[]) - { -     intN; -     //freopen ("Input.txt", "R", stdin); in      while(SCANF ("%d", &n)! =EOF) { -         intEndmax =0; to          for(inti =0; I < n; i++) { +scanf" %d%d%d", &act[i].start, &act[i].end, &act[i].value); -             if(Act[i].end >Endmax) { theEndmax =Act[i].end; *             } $         }Panax NotoginsengQsort (Act,n,sizeof(Project), CMP); -          theMemset (DP,0,sizeof(DP)); +dp[0] = act[0].value; A  the          for(inti =1; I < n; i++) { +Dp[i] = dp[i-1]; -              for(intj = I1; J >=0; j--) { $                 if(Act[j].end <=Act[i].start) { $Dp[i] = max (dp[i-1], Dp[j] +act[i].value); -                      Break; -                 } the             } -Dp[i] =Max (Dp[i], act[i].value);Wuyi         } theprintf"%d\n", dp[n-1]); -     } Wu     return 0; -}

The first code commits an error because there are no 43 lines in this sentence

Nine degrees OJ topic 1499: Project arrangement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.