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. 删边(cip)

    删边(cip) 给出一个没有重边和自环的无向图,现在要求删除其中两条边,使得图仍然保持连通. 你的任务是计算有多少组不合法的选边方案.注意方案是无序二元组. Sol 神题,无从下手啊. 考虑点dfs建 ...

  2. python 栈和队列

    class Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def push ...

  3. 二叉树系列 - 二叉树里的最长路径 例 [LeetCode] Binary Tree Maximum Path Sum

    题目: Binary Tree Maximum Path Sum Given a binary tree, find the maximum path sum. The path may start ...

  4. html 让一行文字居中

    文本在行高范围内垂直居中 可以利用行高特性让一行文本居中 line-height:100px://父容器的高度

  5. UVA 1645 Count

    https://vjudge.net/problem/UVA-1645 题意:有多少个n个节点的有根树,每个深度中所有节点的子节点数相同 dp[i] 节点数为i时的答案 除去根节点还有i-1个点,如果 ...

  6. 洛谷 2957 [USACO09OCT]谷仓里的回声Barn Echoes

    题目描述 The cows enjoy mooing at the barn because their moos echo back, although sometimes not complete ...

  7. nginx 状态监控

    通过查看Nginx的并发连接,我们可以更清除的知道网站的负载情况.Nginx并发查看有两种方法(之所以这么说,是因为笔者只知道两种),一种是通过web界面,一种是通过命令,web查看要比命令查看显示的 ...

  8. MySQL按天,按周,按月,按时间段统计

    MYSQL函数:DATE_FORMAT 例子: select DATE_FORMAT(create_time,'%Y%m%d') days,count(caseid) count from tc_ca ...

  9. 关于cocos2d-x 中 CCEditBox 的输入位置和IOS虚拟键盘位置不重合的bug

    这个文章的名字起的实在是有点长,主要是怕说不清楚. 在IOS上,输入时,我看到过的比较少,就两种,如附件两张图.一个是虚拟键盘的输入框完全是在CCEditBox上,另一张虚拟键盘的输入区域是紧挨着键盘 ...

  10. 【洛谷 P4320】 道路相遇 (圆方树,LCA)

    题目链接 题意:给一张无向图和\(M\)个询问,问\(u,v\)之间的路径的必经之点的个数. 对图建出圆方树,然后必经之点就是两点路径经过的原点个数,用\((dep[u]+dep[v]-dep[LCA ...