Topcoder SRM 623 solution report

Source: Internet
Author: User

See: http://robotcator.logdown.com/posts/231132-topcoder-srm-623


We recommend that you use the plug-in greed 2.0, which is very useful. But I don't know how to add test data by myself. I will study it next time.
Greed 2.0 https://github.com/shivawu/topcoder-greed
250pt
There are n trees on the ring runway, marked as 1 -- N. Some trees are recorded when Alice is running. The number is used to calculate the minimum number of laps.
Question: If you think about it, you will know that the numbers of the trees in a circle are increasing, so that the numbers of adjacent records are not increasing by a circle, so that the number of circles is the least.

class RunningAroundPark {    public:    int numberOfLap(int N, vector<int> d) {      int cnt = 0;      for(int i = 1; i < d.size(); i ++){        if(d[i] <= d[i-1]) cnt ++;      }      return cnt+1;    }};

500pt
A sequence is unknown, but a sequence D is given. d [I] indicates the number of zeros at the end of a [I] converted to binary. Ask how many pairs (I, j) exist in a so that the number of I -- J ranges is the geometric series (proportional series, the public ratio is the real number ).
Question: Considering the digital nature, the difference between a [I] And a [I + 1] d [I + 1]-d [I] is zero, then a [I] shifts left or right. d [I + 1]-d [I] bits get a [I + 1], multiply by 2 ^ (d [I + 1]-d [I]). Therefore, in the range (I, j), D is an arithmetic difference sequence, and A is an proportional sequence in the corresponding range. Small Scope, violent.

Class potentialgeometricsequence {public: int numberofsubsequences (vector <int> d) {int CNT = 0; For (int l = 3; L <= D. size (); L ++) {for (INT I = 0; I <= D. size ()-L; I ++) {int G = d [I + 1]-d [I]; int flag = 1; for (Int J = I + 1; j <I L-1; j ++) {If (d [J + 1]-d [J]! = G) {flag = 0; break;} If (flag = 1) CNT ++;} return CNT + 2 * D. size ()-1; // 2 * D. size ()-1 is the (I, j) logarithm when the sequence length is 1 or 2 }};

1000 PT
Given the set D, the number of subsets of D is required. The product of all elements in the subset is goodvalue.
Question: memory-based search.
Note: because the memory search is recursive, you need to understand the recursive boundary, and if it has been stored, direct return does not require recursive computation.

Division by Division

Forgive me for not playing the division and not division symbols, and the formula is broken. Hope you can advise me.

class GoodSubset {    public:    map<pair<int, int>, int> m;    int dp(int goodValue, vector<int> d, int cur){      if(cur == 0){        if(goodValue == 1) return 1;        else return 0;      }      if(m.find(make_pair(goodValue, cur)) != m.end()){        return m[make_pair(goodValue, cur)];      }      int ans = 0;      if(goodValue%d[cur-1] != 0){        return m[make_pair(goodValue, cur)] = dp(goodValue, d, cur-1);      }else{        ans += dp(goodValue, d, cur-1);        ans %= mod;        ans += dp(goodValue/d[cur-1], d, cur-1);        ans %= mod;        return m[make_pair(goodValue, cur)] = ans;      }    }    int numberOfSubsets(int goodValue, vector<int> d) {      m.clear();      int cnt = dp(goodValue, d, d.size());      if(goodValue == 1) cnt --;      return cnt;    }};

Topcoder SRM 623 solution report

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.