Acdream 1667 Naughty Number One (Acdreamer java session)

Source: Internet
Author: User

"Topic link": Click here~~

"To the effect of the topic":

problem Description

Number one like running ~ like Chasing the Wind's footsteps ~

But the number one will never change the playful and mischievous personality, he often runs to other runways when running. Suppose the number one is running a straight runway, from left to right is runway 1th, runway 2nd, runway 3rd ... And so on, and in order to make a few students more free, there is a total of infinite runway! Number one need to run n steps to reach the end, but as mentioned above, he is still on the original runway every step, or leap to the adjacent runway, of course, the number one will not run outside the runway 1th, because this is a violation of the principle of several! The number one, as the name implies, must start running from Runway 1th, and the same, finally, you have to go back to runway 1th to reach the end. So how many ways to run this n-step? (Two scenarios are considered different when and only if the runway of one of the two scenarios is different)

Inputmultiple sets of data, one integer n (n≤1000) per set of dataOutputfor each set of data, output an integer that represents the number of scenarios that satisfy the test instructions. Sample Input
235
Sample Output
2421
Hint

N=2, the number one can have 1-2-1 or 1-1-12 scenarios

N=3, the number one can have 1-2-1-1 or 1-1-2-1 or 1-2-2-1 or 1-1-1-1 four options

"Thinking" it is easy to think that each step of the plan is the first three states pushed over, that is, the left runway, the current runway, the right track, written as DP is:

  DP[I][J] = dp[i-1][j + 1].add (Dp[i-1][j].add (dp[i-1][j-1]));
Dp[i][j]: means running to J runway ran I step of the program number.

Code:

/** This code was made by herongwei* problem:1667* verdict:accepted* submission date:2015-09-22 19:51:08* time:992ms* M Emory:240620kb*///package ac0901; Import Java.util.*;import Java.io.*;import java.math.*; public class main{public static void Main (String args[]) {Scanner cin = new Scanner (New Bufferedinputstream        (system.in));        int t = Cin.nextint ();         BigInteger dp[][] = new BIGINTEGER[1101][1101]; for (int i=0, i<1100; ++i) {for (int j=0; j<1100; ++j) {dp[i               ][j]=biginteger.zero;        }} Dp[0][0]=biginteger.one;         int n; for (int i=1, i<=1001; ++i) {for (int j=1; j<=1001; ++j) {DP I               [j] = Dp[i-1][j + 1].add (Dp[i-1][j].add (dp[i-1][j-1]));           }} while (Cin.hasnext ()) {n=cin.nextint ();    System.out.println (dp[n+1][1]);    }    }} 


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Acdream 1667 Naughty Number One (Acdreamer java session)

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.