Worm worm worm caterpillar tree Climbing trees ~

Source: Internet
Author: User

For the dynamic planning, I will not say more. Because not yet,

Each question is different, but the general principle is the same. Catch test instructions,

Subject: N tree, Caterpillar in M minutes from p to t route species, caterpillars can only go to the left and right adjacent positions.

Center Code:

For(I=1; I<= m; I+ +) for  (J = 1; j <= N; J+ +) DP[i][j] + = DP[i- 1][j-1] + DP[i-1][j+1];
The number of species that traverse the locations of all possible points of time, and finally the number of M-minute t-trees.
The original title is known 0 time P position is 1. Read the title well.

Original question:
Worm
< Span class= "Sh-symbol" > < Span class= "Sh-number" >    Span style= "font-family:arial; font-size:12px; Font-weight:bold; Color:green; " >time limit:1000/1000 MS (java/others)     memory limit:32768/32768 K (Java/Others) 
Total Submission (s): 3080    accepted submission (s): 1979


Problem description Since seeing the price of Christmas Eve Apple, Lele in his house horizontally planted a row of apple trees, a total of n trees.

Suddenly Lele found a caterpillar on the left P tree (counting starting from 1). In order to see the caterpillar become a butterfly process, Lele at the apple tree to observe for a long time. Although no butterflies were seen, Lele found a pattern: every 1 minutes, the caterpillar would randomly crawl from tree to tree.

For example, the caterpillar in the 2nd tree, after 1 minutes, the worm may be in the 1th tree or the 3rd tree. If the caterpillar is on the 1th tree in the beginning, after 1 minutes, the caterpillar will be on the 2nd tree.

Now tell you the number of apple trees N, as well as the location of the beginning of the first position p, ask, in M minutes, the caterpillar arrived at the T tree, there are altogether how many kinds of walk plan number.
< Span class= "Sh-symbol" > < Span class= "Sh-symbol" > < Span class= "Sh-number" > < Span class= "Sh-symbol" > 
Input This topic contains multiple sets of tests, please process to end of file (EOF).
One row per group of tests, including four positive integers n,p,m,t (meaning see title description, 0<n,p,m,t<100)
< Span class= "Sh-symbol" > < Span class= "Sh-symbol" > < Span class= "Sh-number" > < Span class= "Sh-symbol" > 
Output outputs the total number of scenarios for each set of data in a row.
The problem data guarantees that the answer is less than 10^9
< Span class= "Sh-symbol" > < Span class= "Sh-symbol" > < Span class= "Sh-number" > < Span class= "Sh-symbol" > 
Sample INPUT3 2 4 2 3 2 3 2 
< Span class= "Sh-symbol" > < Span class= "Sh-symbol" > < Span class= "Sh-number" > < Span class= "Sh-symbol" > 
Sample OUTPUT4 0 HintThe first set of tests has the following four methods: 2->1->2->1->2 2->1->2->3->2 2->3->2->1->2 2->3->2->3- >2




AK Code

#include <stdio.h>
#include <string.h>

#define N 105

int main ()
{
int I, J, N, p, M, t;
int dp[n][n];

while (scanf ("%d%d%d%d", &n, &p, &m, &t)! = EOF)
{
memset (DP, 0, sizeof (DP));//multi-instance test, do not forget to clear zero
DP[0][P] = 1;
for (i = 1; I <= m; i++)
{
for (j = 1; J <= N; j + +)
DP[I][J] + = Dp[i-1][j-1] + dp[i-1][j+1];
}
printf ("%d\n", dp[m][t]);
}
return 0;
}

Worm worm caterpillar tree climbing trees ~

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.