这个题的情况可以表示为:每个状态都由两个状态所决定,也就是左边的人传球和右边的人传球,并且这里是求和问题而不是求最值,所以直接把两个状态求和即可。
//#include<pch.h>
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <stack>
#include <iomanip>
#include <cstring>
#include <cmath>
#define DETERMINATION main
#define lldin(a) scanf_s("%lld", &a)
#define println(a) printf("%lld\n", a)
#define reset(a, b) memset(a, b, sizeof(a))
const int INF = 0x3f3f3f3f;
using namespace std;
const double PI = acos(-1);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int mod = 1000000007;
const int tool_const = 19991126;
const int tool_const2 = 2000;
inline ll lldcin()
{
ll tmp = 0, si = 1;
char c;
c = getchar();
while (c > '9' || c < '0')
{
if (c == '-')
si = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
{
tmp = tmp * 10 + c - '0';
c = getchar();
}
return si * tmp;
}
///Untersee Boot IXD2(1942)
/**Although there will be many obstructs ahead,
the desire for victory still fills you with determination..**/
/**Last Remote**/
ll dp[550][550];
int DETERMINATION()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
ll n, m;
cin >> n >> m;
dp[0][1] = 1;//莫名其妙的初始化……也就是传0次,位于第一人的方法是1,但这是后面递推的根本。
for (int i = 1; i <=m; i++)
{
for (int j = 1; j <= n; j++)
{
if (j == 1)
dp[i][j] = dp[i - 1][n] + dp[i - 1][2];//注意边界处理
else if (j == n)
dp[i][j] = dp[i - 1][n - 1] + dp[i - 1][1];
else
dp[i][j] = dp[i - 1][j-1] + dp[i - 1][j+1];
}
}
cout << dp[m][1] << endl;
return 0;
}