Sicily 1763. Passing games

Source: Internet
Author: User

1763. Passing games Constraints

Time limit:1 secs, Memory limit:32 MB

Description

When I was in P.E. class, little teacher often took the students with them to play games. This time, the teacher took the students together to do the passing game.

game rule is this: < Span style= "LINE-HEIGHT:27.027027130127PX; margin:10px 0px ">n A classmate stood in a circle, one of the students holding a ball, when the teacher started passing the whistle, each classmate can pass the ball to their own about two students of one (left and right), when the teacher once again blowing whistle, pass stop, at this time, holding the ball did not go out of the classmate is the loser, We're going to show you a show.

The clever little man raises an interesting question: how many different ways of passing can make the ball start to pass in small hands, passingmtime later, back to the small hands. The two methods of passing are regarded as different methods, and only when the two methods are used, the sequence of the students receiving the ball in the order of catching is different. For example, there3a classmate1number,2number,3number, and suppose the little brute was1number, the ball is passing.3the way back to the little savage hands there1->2->3->1and the1->3->2->1, a total2species.

Input

the input has multiple sets of case, each caseone row with two integers separated by spacesN,m(3<=n<=30,1<=m<=30).

Output

each set of case outputs A row that has an integer that represents the number of methods that conform to test instructions.

Sample Input
3 3
Sample Output

2

#include <stdio.h> #include <string.h> #include <queue>using namespace std;//good DP title//SET DP[I][J] The probability of passing the number of passes for I to a person numbered J, where the target character is marked as 1th//then the probability of passing the number of passes to J's hand is naturally the possibility of passing the number of passes to both sides of the i-1 and//for the target character, the probability of passing 0 is 1, It can be understood that there is only one possibility at the beginning, but it seems to be justified, but the initial state of DP's topic is generally difficult to explain (refer to mathematical induction)//note is a ring, attention to the processing of the boundary int dp[35][35];int DPP (int mans, int times) {    memset (DP, 0, sizeof (DP));    DP[0][1] = 1;    for (int i = 1; I <= times, i++) {for        (int j = 1; J <= Mans; j + +) {            if (j = = 1) {                Dp[i][j] = dp[i-1][ Mans] + dp[i-1][2];            } else if (j = = mans) {                dp[i][j] = dp[i-1][j-1] + dp[i-1][1];            } else {                dp[i][j] = dp[i-1][j-1] + dp[i -1][j + 1];    }} return dp[times][1];} int main () {    int n, m;    while (~SCANF ("%d%d", &n, &m))        printf ("%d\n", DPP (n, m));    return 0;}                           


Sicily 1763. Passing games

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.