Southwest min da oj (recursive)

Source: Internet
Author: User

My math can't be that hard to push.Time limit (normal/java): ms/9000 MS Run memory limit: 65536 KByte
Total Submissions: 49 Tested by: 24

Describe

No problem, how to do it ~

All right, Baidu goes together.

So this problem turned out, only for happy.

Xiao Ming likes to play chess, one day he idle to bored, black and white pieces into a long observation, found black mixed together good ugly ah.

Immediately thought, black and sunspots are not adjacent, placed into a strip, how many kinds of possible?!

Input

Multiple sets of test data (approx. 1w Group)

First line, total number of pieces N (0<n<=1000000)

Output

Only one row, to ensure that sunspots and sunspots are not adjacent, the number of pieces placed in all cases after the result of 1000000007 modulo.

Sample input

1
100

Sample output

2
470199269

Analysis: Set A[i] for the total number of pieces of I, b[i] for the total number of white ending, c[i] for the total number of black chess. Then there is a[i]=b[i]+c[i],b[i]=a[i-1],c[i]=b[i-1];

#include <cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>#include<queue>#include<cstdlib>#include<stack>#include<vector>#include<Set>#include<map>#defineLL Long Long#defineMoD 1000000007#defineINF 0x3f3f3f3f#defineN 1000010using namespacestd;intA[n],b[n],c[n];voidinit () {a[1]=2; b[1]=1; c[1]=1;  for(intI=2; i<=1000000; i++) {B[i]=a[i-1];c[i]=b[i-1]; A[i]=b[i]+C[i]; A[i]%=MoD; }}intMain () {intN;    Init ();  while(SCANF ("%d", &n) >0) {printf ("%d", A[n]); }}
View Code

Southwest min da oj (recursive)

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.