hdoj 2151 Worm【动态规划】
Worm
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3395 Accepted Submission(s):
2188
突然Lele发现在左起第P棵树上(从1开始计数)有一条毛毛虫。为了看到毛毛虫变蝴蝶的过程,Lele在苹果树旁观察了很久。虽然没有看到蝴蝶,但Lele发现了一个规律:每过1分钟,毛毛虫会随机从一棵树爬到相邻的一棵树上。
比如刚开始毛毛虫在第2棵树上,过1分钟后,毛毛虫可能会在第1棵树上或者第3棵树上。如果刚开始时毛毛虫在第1棵树上,过1分钟以后,毛毛虫一定会在第2棵树上。
现在告诉你苹果树的数目N,以及毛毛刚开始所在的位置P,请问,在M分钟后,毛毛虫到达第T棵树,一共有多少种行走方案数。
每组测试占一行,包括四个正整数N,P,M,T(含义见题目描述,0<N,P,M,T<100)
题目数据保证答案小于10^9
第一组测试中有以下四种走法:
#include<stdio.h>
#include<string.h>
#define MAX 110
int main()
{
int n,m,p,t,i,j;
int a[MAX][MAX];//二维数组,表示在第x分钟第y个位置时
//的走法种数
while(scanf("%d%d%d%d",&n,&p,&m,&t)!=EOF)
{
memset(a,0,sizeof(a));
a[0][p]=1; //第0分钟第p个位置是
for(int i=1;i<=m;i++)
{
a[i][1]=a[i-1][2];//因为在首部,只有一种走法,就是走向2
a[i][n]=a[i-1][n-1]; //在尾部也只有一种走法,走向n-1
for(int j=2;j<n;j++)
a[i][j]=a[i-1][j-1]+a[i-1][j+1]; //其余位置都有两种走法
} //走向左边或者右边
printf("%d\n",a[m][t]);
}
return 0;
}
hdoj 2151 Worm【动态规划】的更多相关文章
- HDOJ --- 2151 Worm
Worm Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 2151 Worm
Worm Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...
- hdu 2151 Worm (DP)
Worm Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- (动态规划)Worm -- hdu -- 2151
http://acm.hdu.edu.cn/showproblem.php?pid=2151 Worm Time Limit: 1000/1000 MS (Java/Others) Memory ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- POJ 2151 Check the difficulty of problems (动态规划-可能DP)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4522 ...
- Hdoj 1176 免费馅饼 【动态规划】
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDOJ 1423 Greatest Common Increasing Subsequence -- 动态规划
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1423 Problem Description This is a problem from ZOJ 2 ...
随机推荐
- hdu 1730 Northcott Game 博弈论
很简单的博弈论问题,可以转化为Nim 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> ...
- POJ1860——Currency Exchange(BellmanFord算法求最短路)
Currency Exchange DescriptionSeveral currency exchange points are working in our city. Let us suppos ...
- POJ1416——Shredding Company(DFS)
Shredding Company DescriptionYou have just been put in charge of developing a new shredder for the S ...
- 树莓派raspbian安装配置(基本配置+中文配置+远程桌面+lighttpd+php+mysql)
raspbian为树莓派的官方系统,基于Debian裁剪过的Linux系统 其配置过程如下 烧录镜像 首先从树莓派的官方网站上下载镜像和镜像工具 http://www.raspberrypi.org/ ...
- [转] Android自动化测试之MonkeyRunner录制和回放脚本(四)
测试脚本录制: 方案一: 我们先看看以下monkeyrecoder.py脚本: #Usage: monkeyrunner recorder.py #recorder.py http://mirror ...
- openSession()和getCureentSession()的区别
openSession():永远是打开一个新的session getCureentSession():如果当前环境有session,则取得原来已经存在的session,如果没有,则创建一个新的sess ...
- UVa 1471 (LIS变形) Defense Lines
题意: 给出一个序列,删掉它的一个连续子序列(该子序列可以为空),使得剩下的序列有最长的连续严格递增子序列. 分析: 这个可以看作lrj的<训练指南>P62中讲到的LIS的O(nlogn) ...
- Office启动加载vs。。。项
PowerPoint: 选项->加载项->Chinese Translation Addin->管理[COM加载项]转到->取消Chinese Translation Addi ...
- Android UI设计系统-android selector 开始自定义样式
Selector的结构描述: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:a ...
- 各种兼容的placeholder
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...