标签:
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1176
1 #include<iostream> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 6 int t, n; 7 int pi[100005][12]; 8 int fall[100005][12]; 9 int ans; 10 11 int main(){ 12 ios::sync_with_stdio( false ); 13 14 while( cin >> n, n ){ 15 memset( pi, 0, sizeof( pi ) ); 16 memset( fall, 0, sizeof( fall ) ); 17 ans = 0; 18 t = 0; 19 20 int a, b; 21 for( int i = 0; i < n; i++ ){ 22 cin >> a >> b; 23 fall[b][a]++; 24 t = max( t, b ); 25 } 26 27 pi[1][4] = fall[1][4]; 28 pi[1][5] = fall[1][5]; 29 pi[1][6] = fall[1][6]; 30 for( int i = 2; i <= t; i ++){ 31 for( int j = 0; j <= 10; j++ ){ 32 if( !( i + j >= 5 && i - j >= -5 ) ) continue;//这句不要也能A,个人感觉数据不严谨 33 pi[i][j] = pi[i - 1][j]; 34 if( j > 0 ) pi[i][j] = max( pi[i][j], pi[i - 1][j-1] ); 35 if( j <10 ) pi[i][j] = max( pi[i][j], pi[i - 1][j + 1] ); 36 pi[i][j] += fall[i][j]; 37 } 38 } 39 40 for( int i = 0; i <= 10; i++ ) 41 ans = max( ans, pi[t][i] ); 42 43 cout << ans << endl; 44 } 45 46 return 0; 47 }
标签:
原文地址:http://www.cnblogs.com/hollowstory/p/5350247.html