1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| #include <bits/stdc++.h> #include <algorithm> using namespace std;
const int N = 100010; int dp[N][13];
int main() { int n; while(~scanf("%d",&n)) { if (n == 0) break; int maxt = 0; memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; i++) { int x, t; scanf("%d%d", &x, &t); dp[t][x + 1]++; maxt = max(maxt, t); }
for (int i = maxt - 1; i >= 0; i--) { for (int j = 1; j < 12; j++) { dp[i][j] += max(dp[i + 1][j - 1], max(dp[i + 1][j], dp[i + 1][j + 1])); } }
cout << dp[0][6] << endl; }
return 0; }
|