【Luogu】P3800点收集(DP)
代码
#include<iostream> #include<cstdio> #include<cstring> #include<cctype> #include<cmath> #include<algorithm> using namespace std; inline long long read(){ long long num=0,f=1; char ch=getchar(); while(!isdigit(ch)){ if(ch=='-') f=-1; ch=getchar(); } while(isdigit(ch)){ num=num*10+ch-'0'; ch=getchar(); } return num*f; } int n,m,k,t; int f[40010]; int ans; struct Node{ int x,y,val; }que[10010]; bool cmp(Node a,Node b){ return a.x<b.x; } int main(){ n=read(),m=read(),k=read(),t=read(); for(int i=1;i<=k;++i) que[i]=(Node){read(),read(),read()}; sort(que+1,que+k+1,cmp); for(int i=1;i<=k;++i){ f[i]=que[i].val; for(int j=1;j<i;++j) if(abs(que[i].y-que[j].y)<=t*abs(que[j].x-que[i].x)) f[i]=max(f[i],f[j]+que[i].val); ans=max(ans,f[i]); } printf("%d",ans); return 0; }