51nod1031 (simple Fibonacci sequence)

Source: Internet
Author: User

Title Link: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1031

Test instructions: Chinese question eh ~

Idea: For the case of the X-block Domino, we use a[x] to express its method number, which is more than the x-1 block Domino, a domino, there are two kinds of dominoes to put the method:

1. We can directly add it vertically at the end, then the number of permutations is the first x-1 block of the number of dominoes, that is, a[x-1];

2. We can also put it sideways with the preceding piece of dominoes, then the number of permutations is the number of the first x-2 block dominoes, that is, a[x-2];

So there are a[x]=a[x-1]+a[x-2];

Code:

1#include <bits/stdc++.h>2 #defineMAXN 10103 using namespacestd;4 5 Const intmod=1e9+7;6 7 intMainvoid){8     intA[MAXN], N;9a[0]=1, a[1]=1;TenCIN >>N; One      for(intI=2; i<=n; i++){ AA[i]= (a[i-1]+a[i-2])%MoD; -     } -cout << A[n] <<Endl; the     return 0; -}

51nod1031 (simple Fibonacci sequence)

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.