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))\)取值,其中结点\ ...
随机推荐
- 第一次使用autohotkey的记录
第一次使用autohotkey的记录 原来想着直接用python来做模拟输入的,后面查了一下发现,目前的封装的库不一定能支持输入到游戏里,是的,我是打算用来做游戏辅助的,嘿嘿嘿 暂时来讲,我只是看完了 ...
- httpclient的并发连接问题
昨天的搜索系统又出状况了,几个库同时重建索引变得死慢.经过一个上午的复现分析,确定问题出现httpclient的使用上(我使用的是3.1这个被广泛使用的遗留版本).搜索系统在重建索引时,是并发多个线程 ...
- 如何用万用表判断一个12V蓄电池是否没电
常用的方法如下: 1.找一根细铜丝,接触电瓶的正负极柱,冒火花说明电瓶有电,不冒火花说明没有电. 2.用万用表测量电瓶的电压,12.7V说明满电,11.50V一下说明没有电. 3.找一个12V的灯泡或 ...
- 使用Oracle DBLink进行数据库之间对象的訪问操作
Oracle中自带了DBLink功能,它的作用是将多个oracle数据库逻辑上看成一个数据库,也就是说在一个数据库中能够操作还有一个数据库中的对象,比如我们新建了一个数据database1.我们须要操 ...
- Revit API选择三维视图上一点
start [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)] public class cmdPickP ...
- win8、server 2012 清除winsxs文件夹
使用系统自带的文件清理工具 1.组合键win+x ,选择“命令提示符(管理员)” 复制“dism /online /Cleanup-Image /StartComponentCleanup” 到dos ...
- Xamarin.Forms.Xaml.XamlParseException: MarkupExtension not found for trans:Translate using a PCL in Release Mode
I'm pretty desperate finding the solution for the problem stated below. I have a cross platform solu ...
- 在ASP.NET MVC中通过勾选checkbox来更改select的内容
遇到了这样的一个需求:通过勾选checkbox来更改select的内容. 在没有勾选checkbox之前是这样的: 在勾选checkbox之后是这样的: 想通过ajax异步来实现.所以,从控制器拿到的 ...
- tms web core程序部署
tms web core程序部署 笔者把已经开发好的TMS WEB CORE程序部署到阿里云服务器上面,来作为例子. 1)复制TMS WEB CORE前端程序到服务器的c:\room\ 2)复制TMS ...
- ios之快速枚举
for(UIView * subView in self.view.subviews) { if([subView isKindOfClass:[XYZSeniorQueryView class]]) ...