Report on solving problems of rectangle rectangular Sleeve

Source: Internet
Author: User

Maximum Increment sub-sequence

The inspiration for this to me is:
1, the longest increment subsequence is actually the dynamic scale type without knowing the starting point.
2, the use of dynamic rules on the ordered data (if the rectangle is not sorted, there is no "previous rectangle cannot contain the assertion of the back rectangle" = = "before the number is less than the number of subsequent")

Procedure: Sort + Maximum increment subsequence
Motion regulation equation: F[i]=max (f[j]+1) (1<=j<i, a[j]<a[i]&&b[j]<b[i]) = = The equation of dynamic regulation for the longest increment sub-sequence

1#include <stdio.h>2 inta[1001], b[1001], f[1001];3 voidQsortintLintR)4 {5     intx, Y, mid1, Mid2, temp;6mid1=a[(L+R)/2];7mid2=b[(L+R)/2];8x=l;9y=R;Ten      while(x<=y) One     { A          while(a[x]<mid1| |    (A[X]==MID1&AMP;&AMP;B[X]&LT;MID2)) X + +; -          while(a[y]>mid1| |    (A[Y]==MID1&AMP;&AMP;B[Y]&GT;MID2)) y--; -         if(x<=y) the         { -temp=A[x]; -a[x]=A[y]; -a[y]=temp; +temp=B[x]; -b[x]=B[y]; +b[y]=temp; AX + +; aty--; -         } -     } -     if(l<y) qsort (l, y); -     if(x<r) qsort (x, r); - } in intMain () - { to     intN, I, K, temp, ans=1; +scanf"%d", &n); -      for(i=1; i<=n; i++) the     { *scanf"%d%d", &a[i], &b[i]); $         if(a[i]<B[i])Panax Notoginseng         { -temp=A[i]; thea[i]=B[i]; +b[i]=temp; A         } the     } +Qsort1, n); -      for(i=1; i<=n; i++) $     { $          for(k=1; k<i; k++) -         { -             if(a[i]>a[k]&&b[i]>b[k]&&f[k]+1>F[i]) the             { -f[i]=f[k]+1;Wuyi             } the         } -         if(F[i]>ans) ans=F[i]; Wu     } -printf"%d", ans+1); About     return 0; $}
Full Code

Report on solving problems of rectangle rectangular Sleeve

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.