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))\)取值,其中结点\ ...
随机推荐
- BZOJ.1023.[SHOI2008]cactus仙人掌图(DP)
题目链接 类似求树的直径,可以用(类似)树形DP求每个点其子树(在仙人掌上就是诱导子图)最长链.次长链,用每个点子节点不同子树的 max{最长链}+max{次长链} 更新答案.(不需要存次长链,求解过 ...
- 简单单层bp神经网络
单层bp神经网络是解决线性可回归问题的. 该代码是论文:https://medium.com/technology-invention-and-more/how-to-build-a-simple-n ...
- ELASTIC制图等高级使用
基于上一个安装部署的文档后(ELASTIC 5.2部署并收集nginx日志) http://www.cnblogs.com/kerwinC/p/6387073.html 本次带来一些使用的分享. ki ...
- ios数据保存
- 手机浏览器跳转APP
背景 对于APP来说,回流分享页是最好的最便宜的也是最病毒式的拉新方式.让新用户去下载APP是重要的.对老用户来说,可以直接调起APP也是提升用户体验和让用户有侵入式体验的重要手段.所以我们一起来看看 ...
- 巧用CSS3 :target 伪类制作Dropdown下拉菜单(无JS)
:target 是CSS3 中新增的一个伪类,用以匹配当前页面的URI中某个标志符的目标元素(比如说当前页面URL下添加#comment就会定位到id=“comment”的位置,俗称锚).CSS3 为 ...
- stap 命令
SystemTap accepts script as command line option or external file, for example: * Command-line script ...
- javascript 编辑网页
javascript:document.body.contentEditable='true';document.designMode='on'; void 0 出处:http://zhidao.ba ...
- Delphi来实现一个IP地址输入控件
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- Java Dictionary 类存储键值
字典(Dictionary) 字典(Dictionary) 类是一个抽象类,它定义了键映射到值的数据结构. 当你想要通过特定的键而不是整数索引来访问数据的时候,这时候应该使用Dictionary. 当 ...