hdu-1041 (large number of templates)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1041

Test instructions: The computer has the number 1, to expand the operation, if the encounter 1 becomes "01", if you encounter 0, becomes "10", after a transformation called "01", two Times "1001", three times "01101001",

The number of the 01 sequences that are obtained by the N-Times transformation is 0.

Idea: first hit the table to get regular 1,1,3,5,11,21,43 ...

Find the rules to find

1*2+1=3;

1*2+3=5;

3*2+5=11;

5*2+11=21;

...... ;

After that is the sum of things, because the result is too big, do it with a large number.

#include <iostream>#include<cstdio>#include<string>using namespacestd;stringstr[1010];stringAddstringS1,stringS2) {    if(S1.length () <s2.length ()) {        stringtmp=S1; S1=S2; S2=tmp; }    intL1=s1.length (), l2=s2.length (), i,j;  for(i=l1-1, j=l2-1; i>=0; I--, j--) {S1[i]=Char(S1[i]+ (j>=0? s2[j]-'0':0)); if(s1[i]-'0'>=Ten) {S1[i]=Char((s1[i]-'0')%Ten+'0'); if(i) s1[i-1]++; Elses1="1"+S1; }    }    returnS1;}intMainvoid) {str[1]="0", str[2]="1", str[3]="1", str[4]="3", str[5]="5", str[6]=" One";  for(intI=7; i<=1005; i++) {Str[i]=add (Add (str[i-2],str[i-2]), str[i-1]); }     intN;  while(~SCANF ("%d",&N)) {cout<<str[n]<<Endl; }    return 0;} 

hdu-1041 (large number of templates)

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.