poj 1176 Free Pie

free pie

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 59928    Accepted Submission(s): 21039


Problem Description
It is said that no pies will fall from the sky, but one day Gameboy was walking on the path home when suddenly a lot of pies fell from the sky. Speaking of gameboy's character is really good, this pie doesn't fall anywhere else, it just falls within 10 meters of him. Of course, the pie can't be eaten if it falls on the ground, so gameboy immediately removes his backpack to pick it up. But since no one could stand on either side of the trail, he had to pick it up on the trail. Because gameboy usually stays in the room to play games, although he is a master of agility in the game, in reality, his motor nerves are particularly slow, and he can only catch the falling pie within a range of no more than one meter per second. Now give this trail the coordinates on the icon:

To simplify the problem, assume that the pie falls in the 11 positions 0-10 for the next period of time. Gameboy starts at 5, so in the first second, he can only receive a pie on one of the three positions 4, 5, and 6. Ask the gameboy how many pies at most? (Assuming his backpack can hold an infinite number of pies)
 

Input
There are multiple sets of input data. The first row of each set of data is a positive integer n (0<n<100000), indicating that there are n pies falling on this trail. In the resulting n lines, each line has two integers x, T (0<T<100000), which means that a pie falls on point x at the T second. Multiple pies may fall at the same point in the same second. The input ends when n=0.
 

Output
Each set of input data corresponds to a line of output. Output an integer m, indicating that gameboy may receive at most m pies.
Tip: The amount of input data in this question is relatively large. It is recommended to use scanf to read in. Using cin may time out.

 

Sample Input
 
  
6 5 1 4 1 6 1 7 2 7 2 8 3 0
 

Sample Output
 
  
4
 

Author
lwg

 


Idea: Similar to the problem of taking numbers in a number tower, add them layer by layer. But it should be noted that the first second can only take 4, 5, 6 pies.
Code:
#include <bits/stdc++.h>
using namespace std;
const int AX = 1e5+6;
int dp[AX][15];
int main(){
	int n;
	int x, t;
	while( scanf("%d",&n) && n ){
		int T = 0;
		memset( dp , 0 ,sizeof(dp) );
		for( int i = 0 ; i < n ; i++ ){
			scanf("%d%d",&x,&t);
			x ++;
			if( t != 1 ) dp[t][x]++;
			else if( x == 5 || x == 6 || x == 7 ){
				dp[t][x] ++;
			}
			T = max( T , t );
		}
		for( int i = 2 ; i <= T + 1 ; i ++ ){
			for( int j = 1 ; j <= 11 ; j ++ ){	
				dp[i][j] += max( dp[i-1][j-1] , max(dp[i-1][j+1] , dp[i-1][j]) ) ;
			}
		}
		int res = 0;
		for( int i = 1 ; i <= 11 ; i++ ){
			res = max( res, dp[T+1][i] );
		}
		cout << res << endl;
	}
	return 0 ;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325771484&siteId=291194637