Pascal's Travels HDU
来源:互联网 发布:mac chrome flash 发热 编辑:程序博客网 时间:2024/06/06 07:14
Pascal's Travels
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.
423311213123131104333212131232212051110101111111111110111101-1
307题意:有n行n列数据 ,从(1,1)点出发,每次只向右或向下走,每次走的距离就是所在点的数值,到(n ,n)的共有几种走法。
思路 :有的点可以走的到,有的点永远也到不了,可以用另一个dp数组存到对应点的走法。
首先dp数组清零,并且把起点位置dp[0][0]=1;并开始搜索,
两层for循环经过所有的点,能到达的点的dp值都大于零,从一个点到另一个点,要把这个点的dp值加给到达的那个点的dp值上,注意:(n,n)这个点不要搜了,因为不需要再往下走了。
#include<stdio.h>#include<string.h>long long int dp[60][60];int map[50][50];int main(){ int n; while(~scanf("%d",&n)&&n!=-1) { int i,j,k; memset(dp,0,sizeof(dp)); for(i=0; i<n; i++) for(j=0; j<n; j++) scanf("%1d",&map[i][j]); dp[0][0]=1; for(i=0; i<n; i++) for(j=0; j<n; j++) if(i==n-1&&j==n-1) continue; else if(dp[i][j]) { dp[map[i][j]+i][j]+=dp[i][j]; dp[i][map[i][j]+j]+=dp[i][j]; } printf("%lld\n",dp[n-1][n-1]); } return 0;}
阅读全文
0 0
- Pascal's Travels HDU
- Pascal's Travels HDU
- hdu 1208 Pascal's Travels
- HDU 1208 Pascal's Travels
- hdu 1208 Pascal's Travels
- hdu 1208 Pascal's Travels
- HDU 1208 Pascal's Travels
- HDU 1208 Pascal's Travels
- HDU 1208 Pascal's Travels
- hdu 1208 Pascal's Travels
- hdu 1208 Pascal's Travels--DP
- Pascal's Travels (HDU 1208)
- HDU 1208 Pascal's Travels(dp)
- hdu Pascal's Travels(DP)
- HDU-1208 Pascal's Travels 动态规划
- 1274. Pascal's Travels
- hdu1208 Pascal's Travels
- BIT1021 Pascal's Travels
- Android Stuido启动提示"No JVM installation found.Please install a 32-bit JDK...."
- oracle官网如何下载早期版本的jdk
- C语言———42道自整理面试题
- HTML5之列表
- Linux_ubuntu
- Pascal's Travels HDU
- Android—动画
- 文章标题
- 对安全审计软件的一次安全审计
- 一键收藏近期优质论文:从 NLP 到 CV
- 冬天里的一碗海鲜面
- android之广播制作接收手机信息
- $(document).ready(function(){}) 和$(function(){})的区别
- 将文本框中的数字转化为大写