hdu 1978 記憶化搜尋,hdu1978記憶搜尋

來源:互聯網
上載者:User

hdu 1978 記憶化搜尋,hdu1978記憶搜尋

注意:

dp【i】【j】 表示(i,j)這個點有多少種方式       mark【i】【j】表示這個點是否走過  如果有直接返回dp【i】【j】    dp的求法為所有夢走到點的dp的和

注意mark開始的標記

#include<stdio.h>#include<string.h>#include<iostream>using namespace std;int dp[110][110],mark[110][110],cost[110][110],n,m;int dfs(int x,int y){    int i,j;    if(mark[x][y]) return dp[x][y];    //dp[x][y]=0;    for(i=0;i<=cost[x][y];i++)    {        for(j=0;j<=cost[x][y]-i;j++)        {            int xx=x+i;            int yy=y+j;            if(xx<=0||xx>n||yy<=0||yy>m) continue;            if(mark[xx][yy]==0)             {                mark[x][y]=1;                dfs(xx,yy);            }            dp[x][y]=(dp[x][y]+dp[xx][yy])%10000;        }    }    return dp[x][y];}int main(){    int T,i,j;    scanf("%d",&T);           while(T--)    {        scanf("%d%d",&n,&m);        for(i=1;i<=n;i++)        for(j=1;j<=m;j++)        scanf("%d",&cost[i][j]);        memset(dp,0,sizeof(dp));        memset(mark,0,sizeof(mark));        dp[n][m]=1;        mark[n][m]=1;        printf("%d\n",dfs(1,1));    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.