HDU2881 Jack's struggle (LIS)
来源:互联网 发布:手机直播间源码 编辑:程序博客网 时间:2024/06/05 04:52
HDU2881 Jack’s struggle (LIS)
Description
给定一个n*n的场地,与m个任务,每个任务要求在第t秒时到达(r,c)位置,每一秒你可以向上下左右移动一个单位。第0秒你可以在任意未知,求最多可以完成多少任务。
题解
很容易看出来,我们把任务按照时间排序之后就是一个LIS问题了。
判断是否可以转移就是看时间差是否大于欧几里德距离。
这题可以
#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#define MAXN 10000+10#define max(a,b) (a>b)?a:busing 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 0
- HDU2881 Jack's struggle (LIS)
- hdu 2881 Jack's struggle(DP)
- life‘s a struggle
- Life's A Struggle
- hdu2881
- life's a struggle - 宋岳庭
- life's a struggle - 宋岳庭
- struggle
- Jack's problem
- jack's things
- [rock]Life ’s A Struggle -宋岳庭(转)
- hdu2881 dp
- hdu4352 XHXJ's LIS
- hdu4352XHXJ's LIS
- hdu4352 XHXJ's LIS
- HDOJ4352_XHXJ's LIS
- 【HDU4352】 XHXJ's LIS
- Jack's侧方移位全攻略
- Hibernate_二级缓存3_使用EHCache缓存
- hdu1754 线段树
- [leetcode: Python]303. Range Sum Query
- Windows学习(002)--Windows基础数据类型
- 【思想感悟】站在巨人的肩膀上
- HDU2881 Jack's struggle (LIS)
- ES6 Javascript
- (11)关卡编辑器之细节列表
- HDU 1259
- 2017年华东师范大学网络赛 E
- 反幻方 题目
- 一文学会用 Tensorflow 搭建神经网络
- 可能每个人的路都不一样,说下我的路吧。
- hdu 3507 Print Article 斜率优化dp