Worm(2151)

3 篇文章 0 订阅
*自从见识了平安夜苹果的涨价后,Lele就在他家门口水平种了一排苹果树,共有N棵。

突然Lele发现在左起第P棵树上(从1开始计数)有一条毛毛虫。为了看到毛毛虫变蝴蝶的过程,Lele在苹果树旁观察了很久。虽然没有看到蝴蝶,但Lele发现了一个规律:每过1分钟,毛毛虫会随机从一棵树爬到相邻的一棵树上。

比如刚开始毛毛虫在第2棵树上,过1分钟后,毛毛虫可能会在第1棵树上或者第3棵树上。如果刚开始时毛毛虫在第1棵树上,过1分钟以后,毛毛虫一定会在第2棵树上。

现在告诉你苹果树的数目N,以及毛毛刚开始所在的位置P,请问,在M分钟后,毛毛虫到达第T棵树,一共有多少种行走方案数。
 

Input
本题目包含多组测试,请处理到文件结束(EOF)。
每组测试占一行,包括四个正整数N,P,M,T(含义见题目描述,0<N,P,M,T<100)
 

Output
对于每组数据,在一行里输出一共的方案数。
题目数据保证答案小于10^9
 

Sample Input
  
  
3 2 4 2 3 2 3 2
 

Sample Output
  
  
4 0
Hint
第一组测试中有以下四种走法: 2->1->2->1->2 2->1->2->3->2 2->3->2->1->2 2->3->2->3->2
DP
t,x
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <list> 
#include <map> 
#include <string>
using namespace std; 
#define infinity 2147483647
#define pi 3.1415926535898
#define g 9.81
int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}
int maxx(int a,int b)
{
	return a>=b?a:b;
}
int main()
{
	int n,p,m,t,i,j;
	int dp[100][100];
	while(scanf("%d %d %d %d",&n,&p,&m,&t)!=EOF)
	{
		memset(dp,0,sizeof(dp));
		dp[0][p]=1;
		
		for(i=1;i<=m;i++)
		{
			for(j=1;j<=n;j++)
			{
				dp[i][j]=dp[i-1][j-1]+dp[i-1][j+1];
			}
		}	
		cout <<dp[m][t] <<endl;
	}	
		
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值