• hdu 2881(LIS变形)


    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 = 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<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]+1>dp[i]) dp[i] = dp[j]+1;
                }
                ans = max(ans,dp[i]);
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    vs2010 怎样设置文本编辑窗口和解决方案资源管理器同步?
    google浏览器如何导出书签
    C#面试题
    Inkscape tricks
    jupyter-notebook kernel died
    matplotlib 显示中文
    Ubuntu+apt-get update时的源
    vscode设置出错, 无法自动补全
    Ubuntu+vscode打不开
    Ubuntu+Firefox总是打不开网页
  • 原文地址:https://www.cnblogs.com/liyinggang/p/5379077.html
Copyright © 2020-2023  润新知