You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
693 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m;
int f[N][N];
int main() {
cin >> n >> m;
// 边界第0次传球第1个人获得球的机会数
f[0][1] = 1;
// 传m次球
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (j == 1)
f[i][j] = f[i - 1][j + 1] + f[i - 1][n];
else if (j == n)
f[i][j] = f[i - 1][j - 1] + f[i - 1][1];
else
f[i][j] = f[i - 1][j - 1] + f[i - 1][j + 1];
}
}
// 经过m次传球球回到第1个人手中的机会数
cout << f[m][1] << endl;
return 0;
}