[Topcoder] srm159 div2 Summary

Source: Internet
Author: User

250 points:Give some rules and ask where parking is allowed on the street.

Simply simulate the question and check whether each rule is valid.

Code: streetparking

500 points:Implements the intersection of sets and the difference operation.

Intersection operation: put an array into the set, traverse another array, and check whether each element is in the first set.

Operation: traverses two arrays and puts each element in the two arrays into the set.

Difference calculation: traverse two arrays to check whether the elements in one array do not exist in another array. If they do not exist, they are placed in the final set.

Because the question must be output incrementally, The treeset is used.

Code: Sets

1000 points:Specify a sequence, such as {39,88, 67,5, 69,87, 82,64, 58,61}, to find the longest length of the ascending subsequence (non-consecutive ), and find the number of sub-sequences with such a long increment.

Dynamic Planning, DP [I] = max {DP [J]} (j =, 2 ..., i-1 & Prices [J] <= Prices [I]} + 1; if such J does not exist, DP [I] = 1; that is, find the element that is smaller than prices [I] and has the longest child sequence, and connect Prices [I] to form a new sequence.

Because the maximum number of incrementing subsequences is calculated, data such as {,} appears, the eldest son sequence is 29 31 34 53 86 and 5 6 34 53 86, both of which end with 86, therefore, the length of the sub-sequence that ends with I is always [I] = ways [J] + 1. J is described above.

Code: thepriceisright

[Topcoder] srm159 div2 Summary

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.