dp[ t ]  代表在 t 时刻能获得的最大工资..然后D就是...


Program:

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct node
{
int s,e,p;
}a[1005];
int m,n,dp[105];
bool cmp(node a,node b)
{
return a.s>b.s;
}
int main()
{
int T,i,j,k,ans;
scanf("%d",&T);
while (T--)
{
scanf("%d%d",&m,&n);
for (i=1;i<=n;i++) scanf("%d%d%d",&a[i].s,&a[i].e,&a[i].p);
sort(a+1,a+1+n,cmp);
memset(dp,0,sizeof(dp));
for (;n;n--)
{
k=0;
for (i=0;i<a[n].s;i++)
if (dp[i]>k) k=dp[i];
if (dp[a[n].e]<k+a[n].p)
dp[a[n].e]=k+a[n].p;
}
ans=0;
for (i=0;i<=m;i++)
if (dp[i]>ans) ans=dp[i];
printf("%d\n",ans);
}
return 0;
}