标签:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int f[100007][17]; int num[100007][17]; int max(int a,int b) { return a>b?a:b; } int main() { int n; int tm = 0; int tt; int x,T; while(scanf("%d",&n) && n) { memset(num,0,sizeof(num)); memset(f,0,sizeof(f)); for(int i = 1;i <= n;i++) { scanf("%d%d",&x,&T); num[T][x]++; tm = T>tm?T:tm; } f[1][4] = num[1][4]; f[1][5] = num[1][5]; f[1][6] = num[1][6]; for(int i = 2;i <= tm;i++) for(int j = 0;j <= 10;j++) f[i][j] = max(max(f[i-1][j],f[i-1][j-1]),f[i-1][j+1])+num[i][j]; tt = 0; for(int i = 0;i <= 10;i++) tt = f[tm][i]>tt?f[tm][i]:tt; printf("%d\n",tt); } return 0; }
标签:
原文地址:http://www.cnblogs.com/immortal-worm/p/4949439.html