题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2151

 

分析: DP。
思路:全盘扫描。
     i表示时间,l表示第几棵树,方程:
     step[i][l]=step[i-1][l-1]+step[i-1][l+1]。

 

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#define LL long long
using namespace std;
int dp[110][110];
int main()
{
    int n,p,m,t;
    while(scanf("%d%d%d%d",&n,&p,&m,&t)>0)
    {
        memset(dp,0,sizeof(dp));
        dp[0][p]=1;
        for(int i=1;i<=m;i++)
        {
            dp[i][1]=dp[i-1][2];
            dp[i][n]=dp[i-1][n-1];
            for(int j=2;j<n;j++)
                dp[i][j]=dp[i-1][j-1]+dp[i-1][j+1];
        }
        printf("%d\n",dp[m][t]);
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2021-10-02
  • 2022-02-10
  • 2022-03-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2022-03-09
  • 2022-02-26
  • 2021-11-23
相关资源
相似解决方案