zoukankan      html  css  js  c++  java
  • HDU 1208 Pascal's Travels

    暑假集训的时候做过了,当时大神XX不到30分钟搞定了,我陷入了深搜的陷阱中了。

    题意:从[1,1]出发到[n,n],每次到达的格子都要按照格子里的数字走。问可以走到终点的数量是多少。

    1.明显的递推。每个可能走到的格子都是由上个格子转移来的,那么能到达上一个格子的步数肯定成为到达该格子的数量一部分。

    2.那么将每个格子可能去到的下一个格子都递推下去。只能向下向右走。

    3.递推的方法,或者记忆化搜索。

     1 #include <stdio.h>
     2 #include <iostream>
     3 using namespace std;
     4 
     5 __int64 path[40][40];
     6 int maz[40][40] , n;
     7 
     8 void dp()
     9 {
    10     for(int i=0;i<=n;i++)
    11     {
    12         for(int j=0;j<=n;j++)
    13         {
    14             path[i][j] = 0;
    15         }
    16     }
    17     path[1][1] = 1;
    18     for(int i=1;i<=n;i++)
    19     {
    20         for(int j=1;j<=n;j++)
    21         {
    22             if(i==n && j==n) break;
    23             int t = maz[i][j];
    24             if(path[i][j] > 0)
    25             {
    26                 if(t + i <= n)
    27                 {
    28                     path[t+i][j] += path[i][j];
    29                 }
    30                 if(t + j <= n)
    31                 {
    32                     path[i][j+t] += path[i][j];
    33                 }
    34             }
    35         }
    36     }
    37 }
    38 #include <string.h>
    39 int main()
    40 {
    41     char st[100];
    42     while(scanf("%d",&n) , n >= 0)
    43     {
    44         for(int i=1;i<=n;i++)
    45         {
    46             scanf("%s",st);
    47             for(int j=0;j<strlen(st);j++)
    48             {
    49                 maz[i][j+1] = st[j] - '0';
    50             }
    51         }
    52         dp();
    53         printf("%I64d
    ",path[n][n]);
    54     }
    55     return 0;
    56 }
    View Code
  • 相关阅读:
    ubuntu查看安装的pytorch/cuda版本
    go不使用工具包将大写字符转成小写字符的方法
    使用Nexus搭建Maven私服
    maven setting.xml配置说明
    maven的仓库、生命周期与插件
    maven项目搭建
    maven之详解继承与聚合
    Maven核心概念之依赖,聚合与继承
    commons-logging日志系统
    新建我的 第一个maven项目
  • 原文地址:https://www.cnblogs.com/cton/p/3436838.html
Copyright © 2011-2022 走看看