P1057 传球游戏
题解: d p [ i ] [ j ] = d p [ i + 1 ] [ j − 1 ] + d p [ i − 1 ] [ j − 1 ] dp[i][j] = dp[i + 1][j – 1] + dp[i – 1][j – 1] dp[i][j]=dp[i+1][j−1]+dp[i−1][j−1]表示球传到第 i i i个人传球次数为 j j j的时候的方案数。边界为 d p [ 1 ] [ 0 ] = 1 dp[1][0] = 1 dp[1][0]=1。(这个不用多说叭…)
#include<bits/stdc++.h>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
#endif
int n,m, dp[33][33] = {0};
cin>>n>>m;
dp[1][0] = 1;
for(int i = 1; i <= m; ++i) {
dp[1][i] = dp[2][i - 1] + dp[n][i - 1];
for(int j = 2; j < n; ++j) {
dp[j][i] = dp[j + 1][i - 1] + dp[j - 1][i - 1];
}
dp[n][i] = dp[n - 1][i - 1] + dp[1][i - 1];
}
cout<< dp[1][m] <<endl;
return 0;
}