HDU2881 Jack's struggle (LIS)

3 篇文章 0 订阅

HDU2881 Jack’s struggle (LIS)

Description

给定一个n*n的场地,与m个任务,每个任务要求在第t秒时到达(r,c)位置,每一秒你可以向上下左右移动一个单位。第0秒你可以在任意未知,求最多可以完成多少任务。

题解

很容易看出来,我们把任务按照时间排序之后就是一个LIS问题了。
判断是否可以转移就是看时间差是否大于欧几里德距离。
这题可以 O(n2) 卡过。

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#define MAXN 10000+10
#define max(a,b) (a>b)?a:b
using namespace std;

int n,m,d[MAXN],ans;
struct Date{
    int x,y,t;
}a[MAXN];

bool cmp(const Date a,const Date b) { return a.t < b.t; }

bool check(int i,int j)
{
    if(abs(a[i].x-a[j].x)+abs(a[i].y-a[j].y)>abs(a[i].t-a[j].t)) return 0;
    else return 1;
}
int main()
{
    while(1)
    {
        scanf("%d%d",&n,&m);
        if(n==0&&m==0) break;
        memset(a,0,sizeof(a));
        memset(d,0,sizeof(d));
        ans=0;

        for(int i=1;i<=m;i++)
            scanf("%d%d%d",&a[i].t,&a[i].x,&a[i].y),d[i]=1;

        sort(a+1,a+m+1,cmp);

        for(int i=2;i<=m;i++)
        {   
            for(int j=i-1;j>=1;j--)
                if(check(i,j))
                    d[i]=max(d[i],d[j]+1);
            ans=max(ans,d[i]);
        }
        printf("%d\n",ans);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值