zoukankan      html  css  js  c++  java
  • BZOJ1207 [HNOI2004]打鼹鼠

    Description

    鼹鼠是一种很喜欢挖洞的动物,但每过一定的时间,它还是喜欢 把头探出到地面上来透透气的。根据这个特点阿Q编写了一个打鼹鼠的游戏:在一个n*n的网格中,在某些时刻鼹鼠会在某一个网格探出头来透透气。你可以控制 一个机器人来打鼹鼠,如果i时刻鼹鼠在某个网格中出现,而机器人也处于同一网格的话,那么这个鼹鼠就会被机器人打死。而机器人每一时刻只能够移动一格或停 留在原地不动。机器人的移动是指从当前所处的网格移向相邻的网格,即从坐标为(i,j)的网格移向(i-1, j),(i+1, j),(i,j-1),(i,j+1)四个网格,机器人不能走出整个n*n的网格。游戏开始时,你可以自由选定机器人的初始位置。现在你知道在一段时间 内,鼹鼠出现的时间和地点,希望你编写一个程序使机器人在这一段时间内打死尽可能多的鼹鼠。

    Input

    第 一行为n(n<=1000), m(m<=10000),其中m表示在这一段时间内出现的鼹鼠的个数,接下来的m行每行有三个数据time,x,y表示有一只鼹鼠在游戏开始后 time个时刻,在第x行第y个网格里出现了一只鼹鼠。Time按递增的顺序给出。注意同一时刻可能出现多只鼹鼠,但同一时刻同一地点只可能出现一只鼹 鼠。

    Output

    仅包含一个正整数,表示被打死鼹鼠的最大数目

    Sample Input

    2 2
    1 1 1
    2 2 2

    Sample Output

    1
     
    正解:DP
    解题报告:
      DP水题。然而我前两发wa了,因为没考虑到不一定是最后一个最优,我真傻真的。
      直接枚举从哪一步转移过来,DP尽管复杂度貌似压时,但是不虚。
     
     1 //It is made by jump~
     2 #include <iostream>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <cmath>
     7 #include <algorithm>
     8 #include <ctime>
     9 #include <vector>
    10 #include <queue>
    11 #include <map>
    12 #include <set>
    13 #ifdef WIN32   
    14 #define OT "%I64d"
    15 #else
    16 #define OT "%lld"
    17 #endif
    18 using namespace std;
    19 typedef long long LL;
    20 const int MAXM = 10011;
    21 int n,m,ans;
    22 int f[MAXM];
    23 
    24 struct mouce{
    25     int tim,x,y;
    26 }a[MAXM];
    27 
    28 inline int getint()
    29 {
    30        int w=0,q=0;
    31        char c=getchar();
    32        while((c<'0' || c>'9') && c!='-') c=getchar();
    33        if (c=='-')  q=1, c=getchar();
    34        while (c>='0' && c<='9') w=w*10+c-'0', c=getchar();
    35        return q ? -w : w;
    36 }
    37 
    38 inline void work(){
    39     n=getint(); m=getint();
    40     for(int i=1;i<=m;i++) a[i].tim=getint(),a[i].x=getint(),a[i].y=getint(),f[i]=1;
    41     for(int i=1;i<=m;i++) {
    42     for(int j=i-1;j;j--) {
    43         int x=abs(a[j].x-a[i].x)+abs(a[j].y-a[i].y);
    44         if(x<=a[i].tim-a[j].tim) f[i]=max(f[j]+1,f[i]);
    45     }
    46     }
    47     for(int i=1;i<=m;i++) if(f[i]>ans) ans=f[i];//不一定是最后一个!!!
    48     printf("%d",ans);
    49 }
    50 
    51 int main()
    52 {
    53   work();
    54   return 0;
    55 }
  • 相关阅读:
    Ural 1099 Work Scheduling (一般图的最大匹配:带花树算法)
    HDU 4687 Boke and Tsukkomi (2013.8.20 多校9 1002)(暴力+带花树算法)
    2013 Multi-University Training Contest 9 小结(2013.8.20)
    TeX代码模板(持续更新中)
    POJ 3177 Redundant Paths
    POJ 1904 King's Quest
    hdu 4685 Prince and Princess (2013.8.15 多校8---1010)
    2-SAT模板(修改自LRJ的模板)
    HDU 3622 Bomb Game
    Ubuntu 压缩命令
  • 原文地址:https://www.cnblogs.com/ljh2000-jump/p/5693110.html
Copyright © 2011-2022 走看看