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))\)取值,其中结点\ ...
随机推荐
- Windows上Nginx的安装教程详解
一 背景 为了方便本地的开发和验证,于是整理了这一篇Windows上安装Nginx的博文,建议一般学习还是使用Linux,一般正规公司都是在Linux上安装Nginx服务! 本篇内容相对比较简单,如果 ...
- SCTF2018-Event easiest web - phpmyadmin
6月19日的SCTF的web送分题. 打开链接是一个phpmyadmin的登陆界面,尝试用默认账号:root 密码:root登陆 于是直接进去了,首先看下数据库,除了些初始化的库以外,abc这个库比 ...
- Linux驱动之USB(个人)
USB概述 <USB简介> a:背景 USB是Universal Serial Bus的缩写,是一种全新的,双向同步传输的,支持热插拔的 ...
- python标准库--functools.partial
官方相关地址:https://docs.python.org/3.6/library/functools.html 一.简单介绍: functools模块用于高阶函数:作用于或返回其他函数的函 ...
- android onPause OnSavedInstance
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 活动 的 在暂停时候 这个方法 执行结束后,才会执行 下一个活动的 在创建时候 的那个 ...
- BZOJ.1028.[JSOI2007]麻将(贪心)
题目链接 枚举对子,枚举每张牌,先出完它的刻子,剩下的出顺子.\(O(n^3)\). 不是这样 -> 出完所有刻子,最后出顺子.(日常zz) 优先仨相同的,然后顺子,有一次且一定要用一次机会补顺 ...
- BZOJ2278 : [Poi2011]Garbage
如果两个环相交,那么相交的部分相当于没走. 因此一定存在一种方案,使得里面的环都不相交. 把不需要改变状态的边都去掉,剩下的图若存在奇点则无解. 否则,每找到一个环就将环上的边都删掉,时间复杂度$O( ...
- 群晖NAS使用Docker安装迅雷离线下载出现the active key is not valid.
出现这种情况多半是挂了,也有可能是不稳定的网络,重装Docker镜像可能会解决,只有不断试,没什么好的解决方法.
- html5 js实现浏览器全屏
全屏 var docElm = document.documentElement; //W3C if (docElm.requestFullscreen) { docElm.requestFullsc ...
- Codeforces 235E. Number Challenge DP
dp(a,b,c,p) = sigma ( dp(a/p^i,b/p^j,c/p^k) * ( 1+i+j+k) ) 表示用小于等于p的素数去分解的结果有多少个 E. Number Challenge ...