题目链接:http://poj.org/problem?id=1609
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> #include <queue> #include <vector> using namespace std; const int maxe = 50000; const int maxn = 105; const int INF = 0x3f3f3f; int main() { //freopen("E:\acm\input.txt","r",stdin); int N; int dp[maxn][maxn]; int B[maxn][maxn]; int Maxl,Maxm; while(cin>>N){ memset(dp,0,sizeof(dp)); //dp[i][j]表示最大的l为i,m为j的高度 memset(B,0,sizeof(B)); Maxl = 0, Maxm = 0; if(N == 0) { printf("* "); break; } for(int i=1;i<=N;i++){ int a,b; scanf("%d %d",&a,&b); Maxl = max(Maxl,a); Maxm = max(Maxm,b); B[a][b]++; } int ans = 0; for(int i=1;i<=Maxl;i++) for(int j=1;j<=Maxm;j++){ dp[i][j] = B[i][j] + max(dp[i-1][j] , dp[i][j-1] ); if(B[i][j]) ans = max(ans,dp[i][j]); } printf("%d ",ans); } }