Hdu-2045-not Easy series of (3)--lele RPG puzzles

Source: Internet
Author: User

Recursive ideas:

Hand calculation derivation arr[1]=3, arr[2]=6, arr[3]=6, arr[4]=18;

Deduce arr[n]= at this time? (n>3) Taking into account that the value of n-1 is ① and the first is the same ② is different from the first place;

It is easy to understand that the first bit of n-1 is different (such a method has arr[n-1]) then the nth bit only one value is the first and the n-1 bit, then the total value is equal to arr[n-1];

However, another value of the n-1 bit and the first bit of the same so that the n-2 bit is bound to be different from the 1th (such a method of arr[n-2]) the value of the nth bit of the second is the first, the total value is equal to 2*arr[n-2];

End: Arr[i]=arr[i-1]+2*arr[i-2];(n>3);

#include <iostream> #include <string>using namespace Std;int main () {    long long arr[51]={0, 3, 6, 6};    for (int i=4; i<51; i++)            arr[i]=arr[i-1]+2*arr[i-2];    int N;    while (cin>>n)        Cout<<arr[n]<<endl;return 0;}

  

Hdu-2045-not Easy series of (3)--lele RPG puzzles

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.