/* 具体思路参见:http://hi.baidu.com/dispossessed/item/320544233e27109b9c63d1a6 将每组数据转换为区间以后,然后按照x从小到大排序,便可以用DP来做。注意不符合条件的排除,①处的作用 */ #include <cstdio> #include <cstdlib> #include <cstring> const int nMax = 507; int d[nMax]; int N; struct Node { int x, y; int cnt; }node[nMax]; int cmp(const void *a, const void *b) { Node *pa = (Node *) a; Node *pb = (Node *) b; return pa ->x - pb ->x; } int max(int a, int b) { return a > b ? a : b; } int main() { //freopen("e://data.in", "r", stdin); while(scanf("%d", &N) != EOF) { int i, j; for(i = 0; i < N; ++ i) { scanf("%d%d", &node[i].x, &node[i].y); node[i].cnt = 1; } qsort(node, N, sizeof(node[0]), cmp); for(i = 1, j = 0; i < N; ++ i) { if(node[j].x == node[i].x && node[j].y == node[i].y) node[j].cnt ++; else { if(node[j].cnt > (N - node[j].x - node[j].y))//① node[j].cnt = N - node[j].x - node[j].y; j ++; node[j].x = node[i].x; node[j].y = node[i].y; } } if(node[j].cnt > (N - node[j].x - node[j].y)) node[j].cnt = N - node[j].x - node[j].y; memset(d, 0, sizeof(d)); int up = j; for(i = 0; i <= up; ++ i) { for(j = node[i].x; j >= 0; j --) d[N - node[i].y] = max(d[N - node[i].y], d[j] + node[i].cnt); } int _max = 0; for(i = 0; i <= N; ++ i) if(d[i] > _max) _max = d[i]; printf("%d\n", _max); } return 0; }