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. application.properties 改成 application.yml

    application.properties 改成 application.yml

  2. Spring源码解析-Web容器启动过程

    Web容器启动过程,主要讲解Servlet和Spring容器结合的内容. 流程图如下: Web容器启动的Root Context是有ContextLoaderListener,一般使用spring,都 ...

  3. 重载(Overload)和重写(Override)的区别。重载的方法能否根据返回类型进行区分?

    方法的重载和重写都是实现多态的方式,区别在于前者实现的是编译时的多态性,而后者实现的是运行时的多态性.重载发生在一个类中,同名的方法如果有不同的参数列表(参数类型不同.参数个数不同或者二者都不同)则视 ...

  4. HDU多校(Distinct Values)

    Problem Description Chiaki has an array of n positive integers. You are told some facts about the ar ...

  5. margin和padding

    一.margin基础语法与结构 1.margin语法 Margin:10px Margin的值是数字+html单位,同时也可以为auto(自动.自适应) 2.应用结构 Div{margin:10px} ...

  6. [洛谷P3527] [POI2011]MET-Meteors

    洛谷题目链接:[POI2011]MET-Meteors 题意翻译 Byteotian Interstellar Union有N个成员国.现在它发现了一颗新的星球,这颗星球的轨道被分为M份(第M份和第1 ...

  7. [洛谷P1527] [国家集训队]矩阵乘法

    洛谷题目链接:[国家集训队]矩阵乘法 题目背景 原 <补丁VS错误>请前往P2761 题目描述 给你一个N*N的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第K小数. 输入输出格式 输入 ...

  8. python学习笔记(二)之python简单实践

    1 安装python开发环境 Linux环境下自动安装好了python,可以通过以下命令更新到python最新版本. #echo "alias python=/usr/bin/python3 ...

  9. Vue 双向绑定原理

    Vue.js最核心的功能有两个,一是响应式的数据绑定系统,二是组件系统. 一.访问器属性:Object.defineProperty ECMAScript 262v5带来的新东西,FF把它归入为jav ...

  10. IE浏览器Bug总结

    每每在网上搜索IE浏览器Bug时,总是骂声一片,特别是前端工程师,每天都要面对,IE浏览器特别是IE6,存在很多Bug,对Web标准的支持也拖后腿,但不可否认,IE浏览器是曾经的霸主,它的贡献也是巨大 ...