Brush question--milking Time POJ-3616

Source: Internet
Author: User
/*
A milking problem, the milking people have m working time periods, each time period has a certain output
One time period must be completed before work can be done another time period
After working for a period of time, must rest R time
So, to solve the problem, you can first add the end time of each time period to the R
The maximum output that can be produced is now required for a given m time period


Dp[i], which represents the maximum amount of milking produced during the I time period,
Then Dp[j] (i>j) Dp[i]=max (DP[I],DP[J]+E[I].EF)
*/
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace Std;
struct node{int st,ed,ef;};
Node e[1005];
int n,m,r;
int dp[1005];
BOOL CMP (node A,node b) {
return a.st<b.st| | (A.st==b.st&&a.ed<b.ed);
}
int main () {
while (~SCANF ("%d%d%d", &n,&m,&r)) {
for (int i=0;i<m;i++) {
scanf ("%d%d%d", &e[i].st,&e[i].ed,&e[i].ef);
E[i].ed+=r;
}
Sort (e,e+m,cmp);
for (int i=0;i<m;i++) {
Dp[i]=e[i].ef;
for (int j=0;j<i;j++) {
if (e[j].ed<=e[i].st) {
Dp[i]=max (DP[I],DP[J]+E[I].EF);
}
}
}
int maxx=0;
for (int i=0;i<m;i++) {
Maxx=max (Maxx,dp[i]);
}
printf ("%d\n", Maxx);
}
return 0;
}

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.