标签:
6 5 1 4 1 6 1 7 2 7 2 8 3 0
4
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int a[100005][11]; int dp[100005][11]; int max(int a,int b,int c) { a = (a > b)? a:b; a = (a > c)? a:c; return a ; } int main() { int n,x,t,T; while(scanf("%d",&n) && n != 0) { T = 0; memset(a,0,sizeof(a)); memset(dp,0,sizeof(dp)); while(n--) { scanf("%d%d",&x,&t); a[t][x]++; if(T < t) T = t; } for(int j = 0; j < 11; j++) dp[T][j] = a[T][j]; for(int i = T ; i > 0; i--) { for(int j = 0; j < 11; j++) { if(j == 0) dp[i - 1][j] = a[i - 1][j] + max(dp[i][j] , dp[i][j + 1]); else if(j == 10) dp[i - 1][j] = a[i - 1][j] + max(dp[i][j] , dp[i][j - 1]); else dp[i - 1][j] = a[i - 1][j] + max(dp[i][j - 1],dp[i][j],dp[i][j + 1]); } } printf("%d\n",dp[0][5]); } return 0; }
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int dp[100005][11]; int max(int a,int b,int c) { a = (a > b)? a:b; a = (a > c)? a:c; return a ; } int main() { int n,x,t,T; while(scanf("%d",&n) && n != 0) { T = 0; memset(dp,0,sizeof(dp)); while(n--) { scanf("%d%d",&x,&t); dp[t][x]++; if(T < t) T = t; } for(int i = T ; i > 0; i--) { for(int j = 0; j < 11; j++) { if(j == 0) dp[i - 1][j] = dp[i - 1][j] + max(dp[i][j] , dp[i][j + 1]); else if(j == 10) dp[i - 1][j] = dp[i - 1][j] + max(dp[i][j] , dp[i][j - 1]); else dp[i - 1][j] = dp[i - 1][j] + max(dp[i][j - 1],dp[i][j],dp[i][j + 1]); } } printf("%d\n",dp[0][5]); } return 0; }
标签:
原文地址:http://blog.csdn.net/litter_limbo/article/details/51347328