标签:des style blog http color io os java ar
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2704 Accepted Submission(s): 802
1 //#define LOCAL 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<iostream> 6 using namespace std; 7 const int maxn=20005; 8 const int inf=0x3f3f3f3f; 9 int m; 10 11 struct doll 12 { 13 int w,h; 14 bool operator <(const doll &a)const 15 { 16 if(w==a.w) 17 return h <a.h; //ÉýÐò 18 else 19 return w > a.w ; //½µÐò 20 } 21 }; 22 23 24 doll aa[maxn],ans[maxn]; 25 int dp[maxn]; 26 27 int binary(doll v) 28 { 29 int l=1,r=m,mid; 30 while(l<=r) 31 { 32 mid=l+((r-l)>>1); //降序 33 if(ans[mid].h<=v.h) 34 l=mid+1; 35 else 36 r=mid-1; 37 } 38 return l; 39 } 40 41 int LIS(doll a[],int n) 42 { 43 int i; 44 int res=0; 45 for(i=1;i<=n;i++) 46 { 47 ans[i].h=inf; 48 ans[i].w=inf; 49 } 50 for(i=1 ; i<=n ; i++){ 51 dp[i]=binary(a[i]); 52 if(res<dp[i])res=dp[i]; 53 if(ans[dp[i]].h>a[i].h&&ans[dp[i]].w>a[i].w){ 54 ans[dp[i]].h=a[i].h; 55 ans[dp[i]].w=a[i].w; 56 } 57 } 58 return res; 59 } 60 61 int main() 62 { 63 #ifdef LOCAL 64 freopen("test.in","r",stdin); 65 #endif 66 67 int cas; 68 scanf("%d",&cas); 69 while(cas--){ 70 scanf("%d",&m); 71 for(int i=1;i<=m;i++){ 72 scanf("%d%d",&aa[i].w,&aa[i].h); 73 } 74 sort(aa+1,aa+m+1); 75 printf("%d\n",LIS(aa,m)); 76 } 77 return 0; 78 }
hdu----(1677)Nested Dolls(DP/LIS(二维))
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/gongxijun/p/3992584.html