poj 1036 Gangsters (DP)
阿新 • • 發佈:2018-12-27
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXM=103;
typedef struct People
{
int t,p,s;
}People;
People ple[MAXM];
int f[MAXM];
bool cmp(People p1,People p2)
{
return p1.t<p2.t;
}
int main()
{
int n,k,s;
scanf("%d %d %d",&n,&k,&s);
for (int i=1;i<=n;++i)
scanf("%d",&ple[i].t);
for(int i=1;i<=n;++i)
scanf("%d",&ple[i].p);
for(int i=1;i<=n;++i)
scanf("%d",&ple[i].s);
sort(ple+1,ple+n+1,cmp);
f[0]=0;
ple[0].p=0;ple[0].s=0;ple[0].t=0;
int ans=0;
for(int i=1;i<=n;++i)
{
for (int j=i-1;j>=0;--j)
{
if(f[j]>=ple[j].p)//下一步做差的基礎是第j個人已經進去。 if(abs(ple[i].s-ple[j].s)<=ple[i].t-ple[j].t)
f[i]=max(f[i],f[j]+ple[i].p);
}
ans=max(ans,f[i]);
}
printf("%d\n",ans);
return 0;
}
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXM=103;
typedef struct People
{
int t,p,s;
}People;
People ple[MAXM];
int f[MAXM];
bool cmp(People p1,People p2)
{
return p1.t<p2.t;
}
int main()
{
int n,k,s;
scanf("%d %d %d",&n,&k,&s);
for
scanf("%d",&ple[i].t);
for(int i=1;i<=n;++i)
scanf("%d",&ple[i].p);
for(int i=1;i<=n;++i)
scanf("%d",&ple[i].s);
sort(ple+1,ple+n+1,cmp);
f[0]=0;
ple[0].p=0;ple[0].s=0;ple[0].t=0;
int ans=0;
for(int i=1;i<=n;++i)
{
for
{
if(f[j]>=ple[j].p)//下一步做差的基礎是第j個人已經進去。 if(abs(ple[i].s-ple[j].s)<=ple[i].t-ple[j].t)
f[i]=max(f[i],f[j]+ple[i].p);
}
ans=max(ans,f[i]);
}
printf("%d\n",ans);
return 0;
}