版权声明:虽然我很菜,不过转载请标明出处。 https://blog.csdn.net/Patrickpwq/article/details/86581469
萌新冒泡 这道题比较水 dp有两种做法 这是其中一种
#include<bits/stdc++.h>
const int N=1000005;
const int M=1005;
using namespace std;
int n,m,r,head[N],next[N],f[N];
struct Node
{
int st,ed,ef;
friend istream&operator >>(istream &in,Node &p)
{
in>>p.st>>p.ed>>p.ef;
return in;
}
}a[M];
int main()
{
cin>>n>>m>>r;
for(int i=1;i<=m;i++)
{
cin>>a[i];
next[i]=head[a[i].ed];
head[a[i].ed]=i;
}
for(register int i=1;i<=n;i++)
{
f[i]=f[i-1];
for(int now=head[i];now;now=next[now]) f[i]=max(f[i],f[a[now].st-r]+a[now].ef);
}
cout<<f[n];
return 0;
}