题意:一头奶牛在[l,r]时间内能产奶t升,每次产奶之后要休息m分钟,判断在n分钟内最多能产多少奶
链接:http://poj.org/problem?id=3616
思路:基础dp,从前一个允许时间内转移最大产奶量。状态转移方程:num[i].be - num[j].en >= r ? dp[i] = max ( dp[i], dp[j] + num[i].val ) : dp[i] = dp[i];
注意点:无
以下为AC代码:
Run ID | User | Problem | Result | Memory | Time | Language | Code Length | Submit Time |
14192323 | 130705009 | 1140 | Accepted | 668K | 0MS | G++ | 931B | 2015-05-13 22:42:17 |
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
//#include <unordered_map>
//#include <unordered_set>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define RDI(a) scanf ( "%d", &a )
#define RDII(a, b) scanf ( "%d%d", &a, &b )
#define RDIII(a, b, c) scanf ( "%d%d%d", &a, &b, &c )
#define RS(s) scanf ( "%s", s )
#define PI(a) printf ( "%d", a )
#define PIL(a) printf ( "%d\n", a )
#define PII(a,b) printf ( "%d %d", a, b )
#define PIIL(a,b) printf ( "%d %d\n", a, b )
#define PIII(a,b,c) printf ( "%d %d %d", a, b, c )
#define PIIIL(a,b,c) printf ( "%d %d %d\n", a, b, c )
#define PL() printf ( "\n" )
#define PSL(s) printf ( "%s\n", s )
#define rep(i,m,n) for ( int i = m; i < n; i ++ )
#define REP(i,m,n) for ( int i = m; i <= n; i ++ )
#define dep(i,m,n) for ( int i = m; i > n; i -- )
#define DEP(i,m,n) for ( int i = m; i >= n; i -- )
#define repi(i,m,n,k) for ( int i = m; i < n; i += k )
#define REPI(i,m,n,k) for ( int i = m; i <= n; i += k )
#define depi(i,m,n,k) for ( int i = m; i > n; i += k )
#define DEPI(i,m,n,k) for ( int i = m; i >= n; i -= k )
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
using namespace std;
const double pi = acos(-1);
template <class T>
inline bool RD ( T &ret )
{
char c;
int sgn;
if ( c = getchar(), c ==EOF )return 0; //EOF
while ( c != '-' && ( c < '0' || c > '9' ) ) c = getchar();
sgn = ( c == '-' ) ? -1 : 1;
ret = ( c == '-' ) ? 0 : ( c - '0' );
while ( c = getchar() , c >= '0' && c <= '9' ) ret = ret * 10 + ( c - '0' );
ret *= sgn;
return 1;
}
inline void PD ( int x )
{
if ( x > 9 ) PD ( x / 10 );
putchar ( x % 10 + '0' );
}
const double eps = 1e-10;
const int dir[4][2] = { 1,0, -1,0, 0,1, 0,-1 };
struct node{
int be;
int en;
int val;
friend bool operator < ( const node &a, const node &b ){
if ( a.en != b.en )
return a.en < b.en;
else if ( a.be != b.be )
return a.be < b.be;
else
return a.val < b.val;
}
}num[1005];
int dp[1005];
int m, n, r;
int main()
{
while ( RDIII ( n, m, r ) != EOF ){
num[0].be = num[0].en = - r - 1;
num[0].val = 0;
REP ( i, 1, m ){
RDIII ( num[i].be, num[i].en, num[i].val );
}
sort ( num + 1, num + m + 1 );
clr ( dp, 0 );
int ans = 0;
REP ( i, 1, m ){
rep ( j, 0, i ){
if ( num[i].be - num[j].en >= r ){
dp[i] = max ( dp[i], dp[j] + num[i].val );
}
}
ans = max ( ans, dp[i] );
}
PIL ( ans );
}
return 0;
}