Files
python/TangDou/CSP-J/AcWingTraining/T7/435.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

26 lines
693 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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;
}