HDU-1978How many ways
1.机器人一开始在棋盘的起始点并有起始点所标有的能量。
2.机器人只能向右或者向下走,并且每走一步消耗一单位能量。
3.机器人不能在原地停留。
4.当机器人选择了一条可行路径后,当他走到这条路径的终点时,他将只有终点所标记的能量。

如上图,机器人一开始在(1,1)点,并拥有4单位能量,蓝色方块表示他所能到达的点,如果他在这次路径选择中选择的终点是(2,4)
点,当他到达(2,4)点时将拥有1单位的能量,并开始下一次路径选择,直到到达(6,6)点。
我们的问题是机器人有多少种方式从起点走到终点。这可能是一个很大的数,输出的结果对10000取模。
对于每一组数据第一行输入两个整数n,m(1 <= n,m <= 100)。表示棋盘的大小。接下来输入n行,每行m个整数e(0 <= e < 20)。
6 6
4 5 6 6 4 3
2 2 3 1 7 2
1 1 4 6 2 7
5 8 4 3 9 5
7 6 6 2 1 5
3 1 1 3 7 2
思路:
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- using namespace std;
- int n,m,dp[][],a[][];
- int check(int x,int y)
- {
- if(x< || x>n || y< || y>m)
- return ;
- return ;
- }
- int dfs(int x,int y)
- {
- if(dp[x][y]>=) return dp[x][y];
- dp[x][y] = ;
- int i,j;
- for(i = ; i<=a[x][y]; i++)
- for(j = ; j<=a[x][y]-i; j++)
- {
- if(check(x+i,y+j))
- continue;
- dp[x][y] = (dp[x][y]+dfs(x+i,y+j))%;
- }
- return dp[x][y];
- }
- int main()
- {
- int t,i,j;
- scanf("%d",&t);
- while(t--)
- {
- scanf("%d%d",&n,&m);
- for(i = ; i<=n; i++)
- for(j = ; j<=m; j++)
- scanf("%d",&a[i][j]);
- memset(dp,-,sizeof(dp));
- dp[n][m] = ;
- printf("%d\n",dfs(,));
- }
- return ;
- }
HDU-1978How many ways的更多相关文章
- hdu 1987-How many ways(dp)
解析:假设机器人在(x,y)这个点,能量为power,那么可以到达它右下角曼哈顿距离小于等于power的地方,再以该点为起点继续搜索. 代码如下: #include<cstdio> #in ...
- HDU 1978 How many ways(动态规划)
How many ways http://acm.hdu.edu.cn/showproblem.php?pid=1978 Problem Description 这是一个简单的生存游戏,你控制一个机器 ...
- HDU 2157 How many ways?? 【矩阵经典8】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=2157 How many ways?? Time Limit: 2000/1000 MS (Java/Ot ...
- Hdu 2157 How many ways??(DP||矩阵乘法)
How many ways?? Time Limit:1000 MS Memory Limit: 32768 K Problem Description 春天到了, HDU校园里开满了花, 姹紫嫣红, ...
- HDU 1978 How many ways (DP)
How many ways Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- How many ways??(HDU 2157)
How many ways?? Sample Input 4 4 //n个点,m条路径0 1 //s->t可通0 21 32 32 //询问数0 3 2 //从0到3走两条路可到的方案有多少种0 ...
- hdu 1978 How many ways 记忆化搜索+DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1978 思路很好想: 定义f[i][j]表示从点(i,j)出发到达(n,m)的方法数: 那么对于一切从( ...
- HDU 1978 How many ways(经典记忆化搜索)
S - How many ways Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 1978 How many ways 记忆化搜索 经典例题
How many ways Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 2157 How many ways?? 临接矩阵+快速幂
Problem Description 春天到了, HDU校园里开满了花, 姹紫嫣红, 非常美丽. 葱头是个爱花的人, 看着校花校草竞相开放, 漫步校园, 心情也变得舒畅. 为了多看看这迷人的校园, ...
随机推荐
- HDFS集群balance(3)-- 架构细节
转载请注明博客地址:http://blog.csdn.net/suileisl HDFS集群balance,对应版本balance design 6 如需word版本,请QQ522173163联系索要 ...
- C++中将string类型转换为int, float, double类型 主要通过以下几种方式:
C++中将string类型转换为int, float, double类型 主要通过以下几种方式: # 方法一: 使用stringstream stringstream在int或float类型转换为 ...
- /etc/motd and /etc/issue
/etc/motd and /etc/issue Bash offers an option to include messages in the /etc/motd and the /etc/iss ...
- mui实现退出当前应用
var first = null; var showMenu = false; mui.back = function() { if(showMenu) { closeMenu();} else { ...
- img图片元素下多余空白解决方案
在进行页面的DIV+CSS排版时,遇到IE6(当然有时Firefox下也会偶遇)浏览器中的图片元素img下出现多余空白的问题绝对是常见的对於 该问题的解决方法也是「见机行事」,根据原因的不同要用不同的 ...
- nyoj 76
#include <iostream> using namespace std; int main() { int i,t,n; int a[101]; cin>>t; whi ...
- UFLDL课程学习(一)
章节地址:http://ufldl.stanford.edu/tutorial/supervised/LinearRegression/ 章节名称:线性回归 (Linear Regression) 第 ...
- Remoting 的“传递的引用”理解
WCf是集大成者,具有其他微软的很多技术,其中分布式上很多借助于Remoting,所以研究一下Remoting有助于理解WCF 提到Remoting就不得不涉及到MarshalByRefObject这 ...
- LayoutInflater.inflate() 参数研究
参考连接:http://blog.csdn.net/lovexieyuan520/article/details/9036673 http://www.2cto.com/kf/201407/31305 ...
- 传输层-TCP
UDP协议提供了端到端之间的通讯,应用程序只需要在系统中监听一个端口,便可以进行网络通讯.随着计算机网络的发展,计算机网络所承载的业务越来越多,有些业务数据的传输需要具备可靠性,譬如我们在进行在线聊天 ...