# BZOJ 1642: [Usaco2007 Nov]Milking Time 挤奶时间( dp )

dp( i ) 表示前 i 个时间段选第 i 个时间段的最优答案 , 则 dp( i ) = max( dp( j ) ) + w_i ( 0 < j < i ) , answer = max( dp( i ) ) ( 1 <= i <= m )

-------------------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define rep( i , n ) for( int i = 0 ; i < n ; ++i )
#define clr( x , c ) memset( x , c , sizeof( x ) )
using namespace std;
const int maxn = 1000 + 5;
int R;
struct data {
int l , r , w;
void Read() {
scanf( "%d%d%d" , &l , &r , &w );
r += R;
}
bool operator < ( const data &rhs ) const {
return l < rhs.l;
}
};
data A[ maxn ];
int d[ maxn ];
int main() {
freopen( "test.in" , "r" , stdin );
int n , m;
cin >> n >> m >> R;
rep( i , m )
A[ i ].Read();
sort( A , A + m );
rep( i , m ) {
d[ i ] = 0;
data* o = &A[ i ];
rep( j , i ) {
data &x = *( A + j );
if( x.r <= o -> l )
d[ i ] = max( d[ i ] , d[ j ] );

}
d[ i ] += o -> w;
}
cout << *max_element( d , d + m ) << "\n";
return 0;
}

-------------------------------------------------------------------------------------------

## 1642: [Usaco2007 Nov]Milking Time 挤奶时间

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 609  Solved: 349
[Submit][Status][Discuss]

## Input

1行三个整数NMR.接下来M行，每行三个整数SiEiPi

最大产奶量．

12 4 2
1 2 8
10 12 19
3 6 24
7 10 31

43

## Source

posted @ 2015-06-09 20:36  JSZX11556  阅读(182)  评论(0编辑  收藏  举报