Posts

Showing posts with the label LIS

BZOJ 1207: Whack-a-Mole

Problem Statement 1207: [HNOI2004]打鼹鼠 Time Limit:  10 Sec   Memory Limit:  162 MB Submit:  3975   Solved:  1893 [ Submit ][ Status ][ Discuss ] 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 My Translation Moles appear on a 2-D grid on certain points at certain times. A robot knows when the moles will emerge and where they will emerge, and starts at the most opti...

POJ 1088: Skiing

POJ 1088: Skiing Original Problem Statement Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小。在上面的例子中,一条可滑行的滑坡为24-17-16-1。当然25-24-23-...-3-2-1更长。事实上,这是最长的一条。 Translation On a 2D array, find the longest sequence of entries such that the sequence satisfies the following: For every entry i in the sequence (excluding the last), the entry after it, j, is less than i. For every entry i in the sequence (excluding the last), it is adjacent to the entry after it, j, on the 2D array. How You Should Think Of This Problem Find the longest decreasing subsequence in a 2D array. How To Solve It Instead of thinking how to implement LIS for a 2D array, think about how to convert it into a problem already seen before - well, 1D LIS. Let's store the data in an 1D array and include i...