POJ1036(DP)

思路有点像最长不减子序列的一种O(n^2)的做法。

dp[i]表示以第i个Gangster为结尾的能得到的prosperity的最大值。

dp[i]=max(G[i].p,dp[j]+G[i].p)(0<=j<=i-1)。(第i个不能取时则dp[i]为0)

按时间排序是为了使得新添加的元素只和最末尾的元素比较就够了。

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

struct Gangster
{
	int t,p,s;
};

bool cmp(struct Gangster a,struct Gangster b)
{
	return a.t<b.t;
}

int main()
{
	int n,k,t;
	int i,j;
	int dp[105]={0};
	struct Gangster G[105];
	
	scanf("%d%d%d",&n,&k,&t);
	for (i=0;i<n;i++)
	  scanf("%d",&G[i].t);
	for (i=0;i<n;i++)
	  scanf("%d",&G[i].p);
	for (i=0;i<n;i++)
	  scanf("%d",&G[i].s);  
	  
	sort(G,G+n,cmp);
	
	int maxx=0;
	for (i=0;i<n;i++)
	{
	  int maxn=0;
          if (G[i].t>=G[i].s)
	  {
            for (j=0;j<i;j++)
              if ( abs(G[i].t-G[j].t) >= abs(G[i].s-G[j].s) && dp[j]>maxn)
                maxn=dp[j];
            dp[i]=maxn+G[i].p;
          }
          else
            dp[i]=0;
          if (dp[i]>maxx)
            maxx=dp[i];
	}
	printf("%d\n",maxx);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值