HDU 1208 Pascal ' s Travels (memory Search)

Source: Internet
Author: User

The main topic: each small representative can walk to the right or down a few steps, ask from the top left up to the right down the total number of ways to go.




DP[I][J] How many of these squares are stored.


#include <iostream> #include <cstring>using namespace std;int n;char a[40][40];int S[40][40];__int64 dp[40] [40];int x[]={1, 0};int y[]={0, 1};__int64 dfs (int X, int Y) {    if (Dp[x][y] | |!s[x][y])        return dp[x][y];    int xx, yy;    for (int i=0; i<2; i++)    {        xx=x+x[i]*s[x][y];        Yy=y+y[i]*s[x][y];        if (xx>=0 && xx<n && yy>=0 && yy<n)            Dp[x][y]+=dfs (XX,YY);    }    return dp[x][y];} int main () {    while (cin>>n && n!=-1)    {for        (int i=0; i<n; i++)            cin>>a[i];        for (int i=0, i<n; i++) for            (int j=0; j<n; j + +)                s[i][j]=a[i][j]-' 0 ';        memset (DP, 0, sizeof (DP));        Dp[n-1][n-1]=1;        Cout<<dfs (0,0) <<endl;    }    return 0;}


HDU 1208 Pascal ' s Travels (memory Search)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.