poj1036

动态规划

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<algorithm>
using namespace std;

#define maxn 105

struct Gangster
{
int s, t, p;
}g[maxn];

int n, k, t;
int f[maxn];

bool operator < (const Gangster &a, const Gangster &b)
{
return a.t < b.t;
}

int main()
{
//freopen("t.txt", "r", stdin);
scanf("%d%d%d", &n, &k, &t);
for (int i = 0; i < n; i++)
scanf(
"%d", &g[i].t);
for (int i = 0; i < n; i++)
scanf(
"%d", &g[i].p);
for (int i = 0; i < n; i++)
scanf(
"%d", &g[i].s);
sort(g, g
+ n);
for (int i = 0; i < n; i++)
{
if (g[i].t >= g[i].s)
f[i]
= g[i].p;
else
{
f[i]
= -1;
continue;
}
for (int j = 0; j < i; j++)
if (abs(g[j].s - g[i].s) <= abs(g[i].t - g[j].t))
f[i]
= max(f[i], f[j] + g[i].p);
}
int ans = 0;
for (int i = 0; i < n; i++)
ans
= max(ans, f[i]);
printf(
"%d\n", ans);
return 0;
}

你可能感兴趣的:(poj)