Jack's struggle

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1418    Accepted Submission(s): 471

Problem Description
A team of airborne troops are ready to complete some missions.
The
battlefield was divided into a grid of n*n, this team can be
air-dropped at any place on time 0. In every time unit after landing,
they can go to the grid left, right, up or down to the current grid, or
they can just stay.
On their mission list, each mission is described
as three integers: t, r and c, represents a task that must be completed
exactly at time t on the grid (r, c).
Obviously, with limits of time, not all missions can be done.
The captain, Jack, struggling making decisions, wants to know how many missions they can complete at most.
 
Input
The input contains serveral cases:

For each case:

* The first line contains two integers n and m, 1<=n<=1000,
1<=m<=10000, n represents the size of the battlefield and m
represents the number of missions on the list.

* Following m lines, each one describes a mission using three integers, t, r and c.

No two missions have the same t, r and c.

The input is terminated by n=m=0.

 
Output
One integer in one line represents the maximum number of mission that can be completed.
 
Sample Input
2 2
1 1 1
2 2 2
0 0
 
Sample Output
1
 
题意:输入n m 代表n*n的矩阵和m条询问,每一条询问有三个变量 t r c 代表在第 t 秒到达(r,c)这个点.
问输入的这些询问中最多达到多少个点.
 
题解:能够在第 t 秒到达从这一点到达下一个点,那么两点之间的最短距离必定不能大于 t ,所以这题对 t排序,然后求最长上升子序列就行了.
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
const int M = ;
struct grid{
int t,r,c;
}g[M];
int dp[M];
int cmp(grid a,grid b){
return a.t < b.t;
}
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF,n+m){
for(int i=;i<=m;i++){
scanf("%d%d%d",&g[i].t,&g[i].r,&g[i].c);
}
sort(g+,g+m+,cmp);
int ans = -;
for(int i=;i<=m;i++){
dp[i]=;
for(int j=;j<i;j++){
int usetime = abs(g[i].r-g[j].r)+abs(g[i].c-g[j].c);
if(usetime<=abs(g[j].t-g[i].t)&&dp[j]+>dp[i]) dp[i] = dp[j]+;
}
ans = max(ans,dp[i]);
}
printf("%d\n",ans);
}
return ;
}

hdu 2881(LIS变形)的更多相关文章

  1. hdu 1087(LIS变形)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  2. Super Jumping! Jumping! Jumping!(hdu 1087 LIS变形)

    Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  3. hdu 5256 LIS变形

    给一个数列,问最少修改多少个元素使数列严格递增.如果不是要求“严格”递增,那就是求最长不降子序列LIS,然后n-LIS就是答案.要严格递增也好办,输入的时候用每个数减去其下标处理一下就行了. /* * ...

  4. hdu 5125(LIS变形)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5125 题解: 这个题dp[i][0],dp[i][1]数组分别记录在第i个位置取a[i]和b[i]时 ...

  5. 九度 1557:和谐答案 (LIS 变形)

    题目描述: 在初试即将开始的最后一段日子里,laxtc重点练习了英语阅读的第二部分,他发现了一个有意思的情况.这部分的试题最终的答案总是如下形式的:1.A;2.C;3.D;4.E;5.F.即共有六个空 ...

  6. UVA 437 巴比伦塔 【DAG上DP/LIS变形】

    [链接]:https://cn.vjudge.net/problem/UVA-437 [题意]:给你n个立方体,让你以长宽为底,一个个搭起来(下面的立方体的长和宽必须大于上面的长和宽)求能得到的最长高 ...

  7. HDU 5489 Removed Interval (LIS变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头 ...

  8. HDU 1069 Monkey and Banana DP LIS变形题

    http://acm.hdu.edu.cn/showproblem.php?pid=1069 意思就是给定n种箱子,每种箱子都有无限个,每种箱子都是有三个参数(x, y, z)来确定. 你可以选任意两 ...

  9. hdu 5256 序列变换 (LIS变形)

    序列变换 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

随机推荐

  1. ACE自适配通信环境简介

    转载于:http://www.cnblogs.com/TianFang/archive/2006/12/03/580795.html ACE自适配通信环境 (Adaptive Communicatio ...

  2. iphone6 iPhone6 Plus的导航栏等高度

    iPhone6                                                                                iPhone6 Plus ...

  3. HDU 5586 (dp 思想)

    Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submis ...

  4. Codeforces Round #332 (Div. 2)B. Spongebob and Joke

    B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. Java的位运算符—与(&)、非(~)、或(|)、异或(^)

    位运算符主要针对二进制,它包括了:“与”.“非”.“或”.“异或”.从表面上看似乎有点像逻辑运算符,但逻辑运算符是针对两个关系运算符来进行逻辑运算,而位运算符主要针对两个二进制数的位进行逻辑运算.下面 ...

  6. 【BZOJ1879】【SDOI2009】Bill的挑战 [状压DP]

    Bill的挑战 Time Limit: 4 Sec  Memory Limit: 64 MB[Submit][Status][Discuss] Description Input 第一行:一个整数T, ...

  7. UOJ#31 【UR #2】猪猪侠再战括号序列

    传送门http://uoj.ac/problem/31 大家好我是来自百度贴吧的_叫我猪猪侠,英文名叫_CallMeGGBond. 我不曾上过大学,但这不影响我对离散数学.复杂性分析等领域的兴趣:尤其 ...

  8. 五分钟学习Java8的流编程

    1.概述 Java8中在Collection中增加了一个stream()方法,该方法返回一个Stream类型.我们就是用该Stream来进行流编程的: 流与集合不同,流是只有在按需计算的,而集合是已经 ...

  9. 什么是AMD规范

    AMD规范全称是Asynchronous Module Definition,即异步模块加载机制.从它的规范描述页面看,AMD很短也很简单,但它却完整描述了模块的定义,依赖关系,引用关系以及加载机制. ...

  10. bzoj 1014 splay

    首先我们可以用splay来维护这个字符串,那么对于某两个位置的lcp,维护每个节点的子树的hash,然后二分判断就好了. /************************************** ...