[NOIP2008 Popularization Group] Passing Game
topic description
In physical education class, Xiaoman's teacher often took the students to play games together. This time, the teacher took the students to play the passing game together.
The rules of the game are as follows: nnn students stand in a circle, one of them holds a ball in his hand, and starts to pass the ball when the teacher blows the whistle, each student can pass the ball to one of the two students on the left and right (left and right). When the teacher blew the whistle again, the passing of the ball stopped. At this time, the student who did not pass the ball with the ball is the loser, and he will perform a show for everyone.
The clever Xiaoman raised an interesting question: how many different ways of passing the ball can make the ball passed from Xiaoman's hand, and the passing mmAfter m times, it returned to Xiaoman's hands. Two methods of passing the ball are considered different methods if and only if the sequence of the students receiving the ball in the order of receiving the ball is different in the two methods. For example, there are three classmates1 1No. 1 ,2 2No. 2 ,3 33 , and assume Xiaoman is1 1No. 1 , the ball passed3 3There are 1 1ways to return to Xiaoman's hands 3 times1-> 2 2 2-> 3 3 3-> 1 1 1 and1 11-> 3 3 3-> 2 2 2-> 1 1 1 of2 22 types.
input format
One line with two integers n , m ( 3 ≤ n ≤ 30 , 1 ≤ m ≤ 30 ) n,m(3 \le n \le 30,1 \le m \le 30) separated by spacesn,m(3≤n≤30,1≤m≤30)。
output format
1 1 1 integer, indicating the number of methods that meet the meaning of the question.
Example #1
Sample Input #1
3 3
Sample output #1
2
hint
40% of the data satisfy: 3 ≤ n ≤ 30 , 1 ≤ m ≤ 20 3 \le n \le 30,1 \le m \le 203≤n≤30,1≤m≤20
100% of the data satisfy: 3 ≤ n ≤ 30 , 1 ≤ m ≤ 30 3 \le n \le 30,1 \le m \le 303≤n≤30,1≤m≤30
2008 Popularization Group Question 3
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e9 + 10;
const int N = 1e4;
int n,m;
int f[N][N];
int main(){
cin >> n >> m;
f[0][0] = 1;
for(int i = 0;i < m;i ++)
for(int j = 0;j < n;j ++){
if(f[i][j]){
f[i + 1][(j - 1 + n)%n] += f[i][j];
f[i + 1][(j + 1 + n)%n] += f[i][j];
}
}
cout << f[m][0] << endl;
system("pause");
return 0;
}