poj 1609 dp

时间:2022-09-09 03:42:13

题目链接: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 = ;
const int maxn = ;
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,,sizeof(dp)); //dp[i][j]表示最大的l为i,m为j的高度
memset(B,,sizeof(B));
Maxl = , Maxm = ; if(N == ) { printf("*\n"); break; }
for(int i=;i<=N;i++){
int a,b;
scanf("%d %d",&a,&b);
Maxl = max(Maxl,a);
Maxm = max(Maxm,b);
B[a][b]++;
}
int ans = ;
for(int i=;i<=Maxl;i++)
for(int j=;j<=Maxm;j++){
dp[i][j] = B[i][j] + max(dp[i-][j] , dp[i][j-] );
if(B[i][j]) ans = max(ans,dp[i][j]);
}
printf("%d\n",ans);
}
}