HDU 4502吉哥シリーズの物語——臨時工計画(時間手配の01リュック)
1409 ワード
タイトルの住所:http://acm.hdu.edu.cn/showproblem.php?pid=4502
考え方:まず時間によって並べて、01のバックパックを走ればいいです.1881と似ていますが、それより簡単です.時間は天然の順番です.dp[j]は最後の時間がjのために稼げる一番多くのお金を表しています.
ACコード:
考え方:まず時間によって並べて、01のバックパックを走ればいいです.1881と似ていますが、それより簡単です.時間は天然の順番です.dp[j]は最後の時間がjのために稼げる一番多くのお金を表しています.
ACコード:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long ll;
const int maxn = 40000;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
struct node
{
int s,e,c;
friend bool operator < (node a,node b)
{
return a.e < b.e;
}
}a[1010];
int dp[110];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int m,n;
scanf("%d%d",&m,&n);
for(int i=1; i<=n; i++)
{
scanf("%d%d%d",&a[i].s,&a[i].e,&a[i].c);
}
sort(a+1,a+n+1);
int ans = 0;
memset(dp,0,sizeof(dp));
for(int i=1; i<=n; i++)
{
for(int j=m; j>=a[i].e; j--)
{
dp[j] = max(dp[j],dp[a[i].s-1]+a[i].c);
ans = max(ans,dp[j]);
}
}
printf("%d
",ans);
}
return 0;
}