时间看成纵坐标,位置看成横坐标,然后就是类似数字金字塔。
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int mod = 998244353;
//#define int long long
typedef long long ll;
int n;
int dp[N][20],w[N][20];
signed main(){
IOS
#ifdef ddgo
freopen("C:\\Users\\asus\\Desktop\\ddgoin.txt","r",stdin);
#endif
while(scanf("%d",&n) && n) {
memset(w,0,sizeof(w));
memset(dp,0,sizeof(dp));
int mn = 0;
for(int i=1;i<=n;i++) {
int x,t; scanf("%d %d",&x,&t);
x ++;
w[t][x] += 1;
mn = max(mn,t);
}
for(int i=mn-1;i>=0;i--)
for(int j=1;j<=11;j++)
dp[i][j] = max(max(dp[i+1][j-1] + w[i+1][j-1],dp[i+1][j] + w[i+1][j]),dp[i+1][j+1] + w[i+1][j+1]);
cout<<dp[0][6]<<endl;
}
return 0;
}