博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 2881(LIS变形)
阅读量:5052 次
发布时间:2019-06-12

本文共 2189 字,大约阅读时间需要 7 分钟。

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 
#include
#include
#include
#include
using namespace std;const int M = 10005;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=1;i<=m;i++){ scanf("%d%d%d",&g[i].t,&g[i].r,&g[i].c); } sort(g+1,g+m+1,cmp); int ans = -1; for(int i=1;i<=m;i++){ dp[i]=1; for(int j=1;j
dp[i]) dp[i] = dp[j]+1; } ans = max(ans,dp[i]); } printf("%d\n",ans); } return 0;}

 

转载于:https://www.cnblogs.com/liyinggang/p/5379077.html

你可能感兴趣的文章
supervisord
查看>>
ubuntu10.04安装x264库
查看>>
●数组及应用举例
查看>>
__int128的实现
查看>>
R 读取clipboard内容 (MAC)
查看>>
Problem - 1118B - Codeforces(Tanya and Candies)
查看>>
jdk1.8 api 下载
查看>>
svn 图标不显示
查看>>
getElement的几中属性介绍
查看>>
iOS 使用Quartz 2D画虚线 【转】
查看>>
平面最接近点对
查看>>
HTML列表,表格与媒体元素
查看>>
PHP、Java、Python、C、C++ 这几种编程语言都各有什么特点或优点?
查看>>
ionic android升级检查
查看>>
sld一张图
查看>>
树莓派连接wifi
查看>>
Unable To View Status Diagram [ID 746806.1]
查看>>
为新项目添彩的 10+ 超有用 JavaScript 库
查看>>
spring中的依赖检查
查看>>
学习笔记03_Day09-----Servle与反射()
查看>>