tyvj1008 Pass Game

Source: Internet
Author: User

Background NOIP2008 The third part of the universal group describes the time of physical education, little teacher often take the students to play together. This time, the teacher took the students together to do the passing game.

The rules of the game are like this: N students stand in a circle, one of the students holding a ball, when the teacher began to pass the whistle, each classmate can pass the ball to their own about two students of one (left or right), when the teacher again blowing whistle, pass stop, at this time, Holding the ball did not come out of the classmate is the loser, to show you a show.

The clever little guy raises an interesting question: how many different ways of passing can make the ball begin to pass in the small hand, pass the M-time, and return to the little brute hand. 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, there are 3 students 1th, 2nd, 3rd, and assume that the small is 1th, the ball passed 3 times back to the small hands of the way there are 1->2->3->1 and 1->3->2->1, a total of 2.

Input format input file ball.in A total of two integer n,m (3<=n<=30,1<=m<=30) separated by spaces. Output format output file Ball.out A total of one row, with an integer representing the number of methods that conform to test instructions. Test Sample 1 input
3 3
Output
2
Note 40% data is met: 3<=n<=30,1<=m<=20
100% of the data meet: 3<=n<=30,1<=m<=30
#include <iostream>#include<cstdio>#include<string>#include<cstring>#include<algorithm>using namespacestd;intn,m,f[ the][ the];intMain () {CIN>>n>>m; f[0][1] =1;  for(inti =1; I <= m;i++) {f[i][1] = f[i-1][2] + f[i-1][n]; F[i][n]= f[i-1][n-1] + f[i-1][1];  for(intj =2; J < n;j++) {F[i][j]= f[i-1][j-1] + f[i-1][j+1]; }} cout<<f[m][1]; return 0;} 

tyvj1008 Pass Game

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.