POJ2704 Pascal's Travels (记忆化DP)
来源:互联网 发布:js控制滚动条的位置 编辑:程序博客网 时间:2024/06/10 04:54
Pascal's Travels
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 3697 Accepted: 1583
Description
An n x n game board is populated with integers, one nonnegative integer per square. The goal is to travel along any legitimate path from the upper left corner to the lower right corner of the board. The integer in any one square dictates how large a step away from that location must be. If the step size would advance travel off the game board, then a step in that particular direction is forbidden. All steps must be either to the right or toward the bottom. Note that a 0 is a dead end which prevents any further progress.
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
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
Input
The input contains data for one to thirty boards, followed by a final line containing only the integer -1. The data for a board starts with a line containing a single positive integer n, 4 <= n <= 34, which is the number of rows in this board. This is followed by n rows of data. Each row contains n single digits, 0-9, with no spaces between them.
Output
The output consists of one line for each board, containing a single integer, which is the number of paths from the upper left corner to the lower right corner. There will be fewer than 263 paths for any board.
Sample Input
423311213123131104333212131232212051110101111111111110111101-1
Sample Output
307
题意就是说一个小球从该正方形的左上角滚到右下角,且只能往右和往下,在这两个方向上前进该点的值。
这题没有什么好的算法,只能是DP,我的是N^3。不知道是否可以还可以优化。这个问题的动态方程就是:
知道了这个动态方程,基本上没有什么困难了。
贴上代码:
- POJ2704 Pascal's Travels (记忆化DP)
- hdu 1208 Pascal's Travels (DP记忆化搜索)
- hdoj 1028/poj 2704 Pascal's Travels(记忆化搜索||dp)
- HDU1208:Pascal's Travels(DP)
- HDU1208 Pascal's Travels(DP)
- HDU1208-Pascal's Travels(DP)
- POJ 2704 Pascal's Travels (记忆化搜索裸题)
- HDU 1208 Pascal's Travels(记忆化搜索)
- 【DFS(记忆化)】hdu 1208 Pascal's Travels
- POJ 2704 Pascal's Travels (基础记忆化搜索)
- HDU 1208 Pascal's Travels( 记忆化搜索)
- hdu 1208 Pascal's Travels 记忆化搜索
- HDU--杭电--1208--Pascal's Travels--记忆化搜索--这个也和机器人那个一样算半个DP吧
- hdu 1208 Pascal's Travels--DP
- POJ 2704(Pascal's Travels-裸dp)
- HDOJ 1208 Pascal's Travels(水DP)
- HDU 1208 Pascal's Travels(dp)
- hdu Pascal's Travels(DP)
- 关于OA、SAAS、互联网
- 【转】 快捷方式lnk文件格式详解(英文)(中文)
- 有学电子的同学吗?
- 有人会51吗?
- 一篇好文章和好网站
- POJ2704 Pascal's Travels (记忆化DP)
- Linux内存管理之kmalloc 与 __get_free_page()
- 程序员眼中的编程语言
- AES学习总结
- Win下PHP连接Oracle以及SQL Server
- POJ1992 Jack(DP 记忆化)
- 关于“指定的参数已超出有效值的范围。参数名 utcDate”的解决方案
- 即时战略游戏中如何协调对象移动
- 粉丝眼中的操作系统