P3800 Power收集

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

inline int read()
{
    char c=getchar();int num=0;
    for(;!isdigit(c);c=getchar());
    for(;isdigit(c);c=getchar())
        num=num*10+c-'0';
    return num;
}

const int N=4e3+5;

int n,m,k,t;
int f[N];
struct P
{
    int x,y,val;
    bool operator < (const P &A) const
    {
        return x<A.x;
    }
}p[N];

int ans,tmp;
int main()
{
    n=read(),m=read(),k=read(),t=read();
    for(int i=1;i<=k;++i)
        p[i].x=read(),p[i].y=read(),p[i].val=read();
    sort(p+1,p+k+1);
    int ans=0;
    for(int i=1;i<=k;++i)
    {
        f[i]=p[i].val;
        for(int j=1;j<i;++j)
        {
            if(abs(p[i].y-p[j].y)<=(p[i].x-p[j].x)*t)
                f[i]=max(f[i],f[j]+p[i].val);
        }
        ans=max(ans,f[i]);
    }
    cout<<ans;
    return 0;
}

 

posted @ 2018-09-12 11:11  whymhe  阅读(209)  评论(0编辑  收藏  举报