标签:poj 1609 tiling up blocks michael the kid rece
~~~~
二维的最长上升子序列。n^2算法居然可以水过。。
就不多说了,排个序,然后DP。
题目链接:http://poj.org/problem?id=1609
~~~~
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #define N 11111 using namespace std; struct node { int l,m; }b[N]; bool cmp(node a,node b) { if(a.l==b.l) return a.m<b.m; return a.l<b.l; } int f[N]; int main() { int n; while(~scanf("%d",&n)) { if(n==0) { printf("*\n"); break; } for(int i=1;i<=n;i++) scanf("%d%d",&b[i].l,&b[i].m); sort(b+1,b+n+1,cmp); int c=0,ans=-1; for(int i=1;i<=n;i++) { f[i]=1; for(int j=1;j<i;j++) { if(b[i].l>=b[j].l && b[i].m>=b[j].m) f[i]=max(f[j]+1,f[i]); } ans=max(f[i],ans); } printf("%d\n",ans); } return 0; }
POJ 1609 Tiling Up Blocks.,布布扣,bubuko.com
标签:poj 1609 tiling up blocks michael the kid rece
原文地址:http://blog.csdn.net/darwin_/article/details/38362875