Fifth session Blue Bridge Cup Java Group University campus selection true title _n step

Source: Internet
Author: User

/* (Start of program header comment)

* Copyright and version Declaration section of the program

* Copyright (c) 2016, Guangzhou Science and Technology Trade Vocational College, Department of Information Engineering students

* All rights reserved.

* File name: Blue Bridge Cup title

* Author: Pengjunhau

* Completion Date: April 01, 2016

* Version number: 001

* Description part of task and solution method

* Description of the problem:

There are n-steps. Starting from the ground (level No. 0), the first successive upper steps, up to no more than the nth level
A certain position and then successive steps down the stairs until it returns to the ground. If only 1 or 2 levels are allowed to go up and down each step,
What is the possible number of scenarios for the upper and lower steps?
In particular, standing still at level 0 is a solution.

Data format:

The input line consists of two positive integers n and M.
Outputs an integer that indicates how many legal stair steps there are for an n-level step, and the answer to M-redundancy.

For example: Enter:
2 10007
The program should output
6

* Program output:

"Sample Description 1"
There are 6 kinds of scenarios (where + represents the upper step, which represents the next step):
(1) Do not move in situ
(2) +1-1
(3) +2-2
(4) +2-1-1
(5) +1 +1-2
(6) +1 +1-1-1

Again, for example, enter:
3 14
The program should output:
1

"Sample Description 2"
There are 15 kinds of programs, 14 after the surplus 1.

"Data Size"
For 30% of data,n<=10000;
For 100% of data, n<=10^17,m<=2*10^9.

* End of comment on the program head

*/

On the code:

Import Java.util.Scanner;

public class Test {

public static void Main (string[] args) {
Scanner input=new Scanner (system.in);
int N=input.nextint ();
int M=input.nextint ();

Int[] Walk=new int[n+1]; Number of methods to step up
walk[0]=1;walk[1]=2;
for (int i=2;i<n;i++) {
WALK[I]=WALK[I-1]+WALK[I-2];
}

int sum=1;//method of standing still

for (int i=0;i<n;i++) {
Sum+=walk[i]*walk[i];
}
System.out.println (sum%m);

}

}

Fifth session Blue Bridge Cup Java Group University campus selection true title _n step

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.