http://acm.hdu.edu.cn/showproblem.php?pid=2151
题目大意:
因为平安夜苹果涨价(嘻嘻,明天恰好平安夜有木有,提前祝大家平安夜快乐)
Lele就在他家门口水平种了一排苹果树,共有N棵。
他发现在左起第P棵树上的一只毛毛虫每1分钟毛毛虫会随机从一棵树爬到相邻的一棵树上,求M分钟后到达T棵树的方案数。
思路:
典型的DP水题。。。
五分钟A掉了
看代码你就懂了。。
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
const int MAXN=103;
int main()
{
int n,m,p,t;
while(~scanf("%d%d%d%d",&n,&p,&m,&t))
{
int dp[MAXN][MAXN]={0};
dp[0][p]=1;
for(int i=0;i<m;i++)
{
for(int j=1;j<=n;j++)
if(dp[i][j])
{
dp[i+1][j+1]+=dp[i][j];
dp[i+1][j-1]+=dp[i][j];
}
}
printf("%d\n",dp[m][t]);
}
return 0;
}