HDU 2151 Worm

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3875    Accepted Submission(s): 2503

Problem Description

自从见识了平安夜苹果的涨价后,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

Author

Linle

Source

ACM程序设计期末考试——2008-01-02(3 教417)

Recommend

lcy

输错题号,进了这题,虽然题很水,还是写了一下

@NOIP传球游戏 ←那题还要处理环,这里连环都没有

动规,f[i][j]=f[i-1][j-1]+f[i-1][j+1]

 1 /**/
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cmath>
 5 #include<cstring>
 6 #include<algorithm>
 7 using namespace std;
 8 const int mxn=200;
 9 int n,p,m,t;
10 int f[mxn][mxn];
11 int main(){
12     int i,j;
13     while(scanf("%d%d%d%d",&n,&p,&m,&t)!=EOF){
14         memset(f,0,sizeof f);
15         f[0][p]=1;
16         for(i=1;i<=m;i++)
17          for(j=1;j<=n;j++){
18              f[i][j]+=f[i-1][j-1]+f[i-1][j+1];
19          }
20         printf("%d\n",f[m][t]);
21     }
22     return 0;
23 }
时间: 2025-01-07 13:22:17

HDU 2151 Worm的相关文章

hdu 2151 Worm (DP)

Worm Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2637    Accepted Submission(s): 1707 Problem Description 自从见识了平安夜苹果的涨价后,Lele就在他家门口水平种了一排苹果树,共有N棵.突然Lele发现在左起第P棵树上(从1开始计数)有一条毛毛虫.为了看到毛毛虫变蝴蝶的过程

(动态规划)Worm -- hdu -- 2151

http://acm.hdu.edu.cn/showproblem.php?pid=2151 Worm Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3403    Accepted Submission(s): 2194 Problem Description 自从见识了平安夜苹果的涨价后,Lele就在他家门口水平种了一排苹果树,共有

hdu 2151

就是一个dp,数组内存的步数, 数组没清空,wa了一次 #include<cstdio> #include<algorithm> #include<cstring> using namespace std; int step[110][110]; int main() { int N,P,M,T; while(scanf("%d%d%d%d",&N,&P,&M,&T)!=EOF){ memset(step,0,size

杭电OJ(HDU)-ACM Steps-Chapter Two-《Biker&#39;s Trip Odometer》《Climbing Worm》《hide handkerchief》《Nasty Hac》

1.2.1 Biker's Trip Odometer #include<stdio.h> #include<math.h> const double PI=acos(-1.0); /* 计算题,根据公式做就行,PI*d*r/(12*5280);res1/t*3600; Sample Input 26 1000 5 27.25 873234 3000 26 0 1000 Sample Output Trip #1: 1.29 928.20 Trip #2: 1179.86 1415

hdu 1049 Climbing Worm

Problem Description An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches. The process of climbing and

HDU 2782 The Worm Turns (DFS)

Winston the Worm just woke up in a fresh rectangular patch of earth. The rectangular patch is divided into cells, and each cell contains either food or a rock. Winston wanders aimlessly for a while until he gets hungry; then he immediately eats the f

HDU 1049.Climbing Worm【水!水!水!】【8月25】

Climbing Worm Problem Description An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches. The process of

【贪心专题】HDU 1049 Climbing Worm (爬井趣题)

链接:click here~~ 题意: 题目大致意思是一个虫子掉在了一个n长度深的井中,然后它每分钟可以爬u长度,然后要休息一分钟,在此期间它会掉下d长度,问最终爬出井需要多久. 简单模拟: 代码: #include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <algorithm> using namespace std; int ma

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116