354. Russian Doll Envelopes

Source: Internet
Author: User

From the time I spent watching, I was in a tangle sort of long. Pay attention to the comparator of the writing, later will be good ~

The algorithm is to sort the size of the envolope, then for each envelope after sorting, it can be loaded into the maximum number of small envelopes, is the length and width of the envelope is smaller than it in a maximum of +1. And 368 of what was done before. Largest divisible subset idea is the same, even more simple.

Dynamic regulation.

1     Static classMysortImplementscomparator<int[]> {2          Public intCompareint[] O1,int[] O2) {3              for(inti = 0; i < o1.length; i++) {4                 if(O1[i]! =O2[i]) {5                     returnO1[i]-O2[i];6                 }7             }8             return0;9         }Ten     } One      A      Public intMaxenvelopes (int[] envelopes) { -         if(Envelopes.length = = 0 | | envelopes[0].length = = 0) { -             return0; the         } -Mysort Mysort =NewMysort (); - Arrays.sort (envelopes, mysort); -         intLen =envelopes.length; +         int[] res =New int[Len]; -         intmax = 1; +          for(inti = 0; i < Len; i++) { ARes[i] = 1; at         } -          for(inti = 1; i < envelopes.length; i++) { -              for(intj = i-1; J >= 0; j--) { -                 if(Envelopes[i][0] > Envelopes[j][0] && envelopes[i][1] > envelopes[j][1]) { -Res[i] = Math.max (Res[j] + 1, Res[i]); -Max =Math.max (Max, res[i]); in                 } -             } to         } +         returnMax;  -}

354. Russian Doll Envelopes

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.