Nine degrees [1084] integer split

Source: Internet
Author: User

1#include <iostream>2  3 using namespacestd;4  5 intdp[1000001];6  7 intMain () {8     intN;9      while(Cin >>N) {Tendp[1] =1; Onedp[2] =2; A      for(inti =3; I <= N; ++i) { -         ifI2==1) -Dp[i] = dp[i-1]; the         Else -Dp[i] = dp[i-1] + dp[i/2]; -Dp[i]%=1000000000; -     } +cout << Dp[n] <<Endl; -     } +  

Excerpt: I is odd, split with the previous i-1 is the same, write a few groups on their own to know, do not say more. The key is that I is even when: when the split is not included in the 1 o'clock, the split is the smallest to 2, then the split with I/2 is one by one corresponding, when the split contains 1 o'clock, the first to take this 1 out, the remaining i-1 to split, the situation with the i-1 of the split to one of the corresponding , and the two split cases are disjoint (because one does not have 1, one has 1), then the addition of I is even when the split case.

Good way, I can't think of whining

Nine degrees [1084] integer split

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.