标签:
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxt = 100000 + 10;
int dp[maxt][11];
int a[maxt][11];
int main(){
int n,x,t,maxT;
while (~scanf("%d",&n) && n){
maxT = 0;
memset(a,0,sizeof(a));
for(int i = 0;i < n ; ++i){
scanf("%d%d",&x,&t);
++a[t][x];
if(t > maxT) maxT = t;
}
memset(dp,0,sizeof(dp));
dp[1][4] = a[1][4];dp[1][5] = a[1][5];dp[1][6] = a[1][6];
for(int i = 2;i <= maxT;++i){
for(int j = 0;j < 11;++j){
dp[i][j] = max(dp[i - 1][j],dp[i][j]);
if(j - 1 >= 0)
dp[i][j] = max(dp[i - 1][j - 1],dp[i][j]);
if(j + 1 <= 10)
dp[i][j] = max(dp[i - 1][j + 1],dp[i][j]);
dp[i][j] += a[i][j];
}
}
int ans = 0;
for(int i = 0;i < 11;++i){
ans = max(dp[maxT][i],ans);
}
printf("%d\n",ans);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/qhy285571052/p/9136c74d6f8d1264595b101495edd8e4.html