HDU1208:Pascal's Travels(DP)
Consider the 4 x 4 board shown in Figure 1, where the solid circle identifies the start position and the dashed circle identifies the target. Figure 2 shows the three paths from the start to the target, with the irrelevant numbers in each removed.
Figure 1
Figure 2
2331
1213
1231
3110
4
3332
1213
1232
2120
5
11101
01111
11111
11101
11101
-1
0
7
Hint
Brute force methods examining every path will likely exceed the allotted time limit.
64-bit integer values are available as "__int64" values using the Visual C/C++ or "long long" values
using GNU C/C++ or "int64" values using Free Pascal compilers.
题意:每一个代表下次能横向或者纵向走几步,问从左上走到右下要走几步
思路:一道DP题,dp数组用来存放到达坐标i,j,要走的步数即可,并没要求最大或者最小
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int n,i,j,k;
__int64 dp[40][40];
int map[40][40];
char s[40]; int main()
{
while(~scanf("%d",&n),n+1)
{
for(i = 0; i<n; i++)
{
scanf("%s",s);
for(j = 0; j<n; j++)
{
map[i][j] = s[j]-'0';
}
}
memset(dp,0,sizeof(dp));
dp[0][0] = 1;
for(i = 0; i<n; i++)
{
for(j = 0; j<n; j++)
{
if(!map[i][j] || !dp[i][j])
continue;
if(i+map[i][j]<n)//不越界
dp[i+map[i][j]][j]+=dp[i][j];
if(j+map[i][j]<n)
dp[i][j+map[i][j]]+=dp[i][j];
}
}
printf("%I64d\n",dp[n-1][n-1]);
}
return 0;
}
HDU1208:Pascal's Travels(DP)的更多相关文章
- HDU 1208 Pascal's Travels 经典 跳格子的方案数 (dp或者记忆化搜索)
Pascal's Travels Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- POJ 2704 Pascal's Travels 【DFS记忆化搜索】
题目传送门:http://poj.org/problem?id=2704 Pascal's Travels Time Limit: 1000MS Memory Limit: 65536K Tota ...
- hdu 1208 Pascal's Travels
http://acm.hdu.edu.cn/showproblem.php?pid=1208 #include <cstdio> #include <cstring> #inc ...
- 【HDOJ】1208 Pascal's Travels
记忆化搜索.注意当除右下角0外,其余搜索到0则返回. #include <algorithm> #include <cstdio> #include <cstring&g ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- HDU 1208 跳格子题(很经典,可以有很多变形)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1208 Pascal's Travels Time Limit: 2000/1000 MS (Java ...
- BZOJ_3049_[Usaco2013 Jan]Island Travels _状压DP+BFS
BZOJ_3049_[Usaco2013 Jan]Island Travels _状压DP+BFS Description Farmer John has taken the cows to a va ...
- hdu1208 dp
题意:给了一个 n * n 的方格图,要从图的左上角走到右下角 ,每次只能向右或者向下走,走的格数为当前格子上的数字,问共有多少中走法. 一开始我看到之后觉得这题完全可以用记忆化搜索来做,dfs 一遍 ...
- Rikka with Travels(2019年杭电多校第九场07题+HDU6686+树形dp)
目录 题目链接 题意 思路 代码 题目链接 传送门 题意 定义\(L(a,b)\)为结点\(a\)到结点\(b\)的路径上的结点数,问有种\(pair(L(a,b),L(c,d))\)取值,其中结点\ ...
随机推荐
- java List/ArrayList 解惑
导读:祖传挖坟派学习方法(宝儿姐友情支持) 第一部分 List简介 第二部分 何为ArrayList 第三部分 代码示例 第四部分 吹牛 如果你急需想搞清楚一些问题可以先看这里的总结 再后续看 ...
- Java HashMap 分析四篇连载
Java的HashMap非常的常用,本篇研究它的实现算法,最后希望计算出内存占用,性能的量化数据,然后得出什么时候使用HashMap,什么时候不能滥用的结论. HashMap实际上是一个数组,数组里 ...
- mysql存储引擎innodb、myisam区别
MyISAM与InnoDB的区别是什么? 1. 存储结构 MyISAM:每个MyISAM在磁盘上存储成三个文件.第一个文件的名字以表的名字开始,扩展名指出文件类型..frm文件存储表定义.数据文件的扩 ...
- 快速沃尔什变换与k进制FWT
这是一篇用来卖萌的文章QAQ 考虑以下三类卷积 \(C_k = \sum \limits_{i \;or\;j = k} A_i * B_j\) \(C_k = \sum \limits_{i\;an ...
- 洛谷.3381.[模板]最小费用最大流(zkw)
题目链接 Update:我好像刚知道多路增广就是zkw费用流.. //1314ms 2.66MB 本题优化明显 #include <queue> #include <cstdio&g ...
- lua中的pairs和ipairs差别
pairs Returns three values: the next function, the table t, and nil, so that the construction for k, ...
- 如何利用 jQuery 修改 css 中带有 !important 的样式属性?
使用 jQuery 修改 css 中带有 !important 的样式属性 外部样式为: div.test { width:auto !important; overflow:auto !import ...
- Go - 反射中 函数 和 方法 的调用 - v.Call()
上一篇文章 说到了 Golang 中的反射的一些基本规则,重点就是文章中最后的三点,但是这篇文章并没有说如何在反射中调用函数和方法,这就是接下来要说的. 反射中调用 函数 众所周知,Golang 中的 ...
- Visual Studio断点调试, 无法监视变量, 提示无法计算表达式
在使用Visual Studio 2012进行断点调试时,对某个变量添加监视,出现"无法计算表达式"的提示. 解决办法:依次点击菜单栏中的"调试"→" ...
- TStream实现多表查询
TStream实现多表查询 function TynFiredac.QuerySQLS(const ASQL, ASQL2: string; AStorageFormat: string = 'bin ...