UVa 1647 (Recursive) Computer transformation

Source: Internet
Author: User

Test instructions

There is a 01 string, each step will be all 0 to 10, will all 1 into 01, the string is the first 1.

After the nth step, the number of 00

Analysis:

At the beginning of the time is still relatively chaotic, I also tangled up 000 is a 00 or 2 00

After you finally want to understand, there will not be such a substring.

Summed up several points:

    • After the nth step, the string length is 2n, and the number of 0 and 1 is equal, respectively 2n-1
    • 1 after a two-step change of 1001, so each 1 after a two-step change will get a 00, and this 00 is left and right on both sides of a 1-pack, will not be with other numbers to gather extra 00
    • 0 after a two-step change of 0110, so 00 will become011 110, so 00 changes two times still have 00

Finally, the conclusion is drawn:

so that f (n) is the number of 00 in the string after n changes, there is a recursive relationship f (n+2) = f (n) (two times the number of 00 before the change) + 2n-1 (two changes before the number of 1)

Because n can be as big as 1000, so use high precision.

1#include <iostream>2#include <cstdio>3 using namespacestd;4 5 inta[1005][ Max], b[1005][ Max];6 7 intMain ()8 {9a[0][0] = a[1][0] =1;Ten      for(inti =2; I <= +; i++) One          for(intj =0; J <135; J + +) A         { -A[I][J] + = a[i-1][J] + a[i-1][j]; -B[I][J] + = b[i-2][J] + a[i-2][j]; thea[i][j+1] + = A[i][j]/10000; A[I][J]%=10000; -b[i][j+1] + = B[i][j]/10000; B[I][J]%=10000; -         } -  +     intN; -      while(SCANF ("%d", &n) = =1) +     { A         inti; at          for(i =135; i >0&& B[n][i] = =0; i--); -printf"%d", B[n][i]); -          for(i--; I >=0; i--) printf ("%04d", B[n][i]); -printf"\ n"); -     } -  in     return 0; -}
code June

UVa 1647 (Recursive) Computer transformation

Related Article

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.