#include <iostream>
#include <string>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#define maxn 35
using namespace std;
int n, m;
long long dp[maxn][maxn];
int main()
{
//freopen("data.in","r",stdin);
ios::sync_with_stdio(false);
cin >> n >> m;//n个人,传m次
memset(dp, 0, sizeof(dp));
//传递0次,娃娃在1号手上方案数
dp[0][1] = 1;
for(int j = 2; j <= n; ++j) {
dp[0][j] = 0;
}
for(int i = 1; i <= m; ++i) {//传递次数
for(int j = 1; j <= n; ++j) {//在j号人手上
if(j == 1) {
dp[i][j] = dp[i-1][j+1] + dp[i-1][n];
continue;
}
if(j == n) {
dp[i][j] = dp[i-1][1] + dp[i-1][j-1];
continue;
}
dp[i][j] = dp[i-1][j-1] + dp[i-1][j+1];
}
}
cout << dp[m][1] << endl;
return 0;
}
计蒜客 蒜头君的新游戏(DP)
猜你喜欢
转载自blog.csdn.net/ccshijtgc/article/details/80893168
今日推荐
周排行