Hdu1041 computer Transformation

Source: Internet
Author: User

The meaning of the question is clear, mainly to find the recursive formula:

Sum [I] = sum [I-1] + 2 * sum [I-2];

Large numbers are required, but this common addition of large numbers is very familiar.

# Include <iostream> # include <algorithm> using namespace STD; int sum [1010] [100], Len [1010]; void Init () {sum [0] [0] = 0; Len [0] = 0; sum [1] [0] = 0; Len [1] = 0; sum [2] [0] = 1; Len [2] = 0; For (INT I = 3; I <= 1000; I ++) {int K, J; k = 0; For (j = 0; j <= Len [I-2]; j ++) {int temp = sum [I-1] [J] + sum [I-2] [J] * 2 + k; k = temp/10000; sum [I] [J] = TEMP % 10000;} while (j <= Len [I-1]) {int temp = sum [I-1] [J] + K; k = temp/10000; sum [I] [J] = TEMP % 10000; j ++;} If (K! = 0) {sum [I] [J] = K; Len [I] = J;} else Len [I] = J-1;} int main () {Init (); int N; while (scanf ("% d", & n) = 1) {int L = Len [N]; printf ("% d ", sum [N] [l]); For (INT I = L-1; I> = 0; I --) printf ("% 04d", sum [N] [I]); printf ("\ n");} return 0 ;}

 

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.