HDU 2151 Worm

http://acm.hdu.edu.cn/showproblem.php?pid=2151

View Code
#include <stdio.h>
#include <string.h>
int n,p,m,t ;
int dp[110][110] ;
int main()
{
    while(~scanf("%d%d%d%d",&n,&p,&m,&t))
    {
        memset(dp,0,sizeof(dp)) ;
        dp[0][p]=1 ;
        for(int i=0;i<=m;i++)
            for(int j=1;j<=n;j++)
            {
                if(j>=2)
                    dp[i+1][j-1]+=dp[i][j] ;
                if(j<n)
                    dp[i+1][j+1]+=dp[i][j] ;
            }
        printf("%d\n",dp[m][t]) ;
    }
    return 0 ;
} 
原文地址:https://www.cnblogs.com/xiaohongmao/p/2544206.html