zoukankan      html  css  js  c++  java
  • HDU 1078 FatMouse and Cheese (记忆化搜索+dp)

    详见代码

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <memory.h>
     5 using namespace std;
     6 const int inf=0x3f3f3f3f;
     7 int a[110][110];
     8 int dp[110][110];//表示到i,j的最大路径和
     9 int dir[4][2]= {1,0,-1,0,0,1,0,-1};
    10 int n,m;
    11 int dfs(int x,int y)
    12 {
    13     int ans=0;
    14     if(!dp[x][y])
    15     {
    16         for(int i=1; i<=m; i++)
    17         {
    18             for(int j=0; j<4; j++)
    19             {
    20                 int xx=x+dir[j][0]*i;
    21                 int yy=y+dir[j][1]*i;
    22                 if(xx<1||xx>n||yy<1||yy>n)
    23                 {
    24                     continue;
    25                 }
    26                 if(a[xx][yy]>a[x][y])
    27                 {
    28                     ans=max(ans,dfs(xx,yy));
    29                 }
    30             }
    31         }
    32         dp[x][y]=ans+a[x][y];
    33     }
    34     return dp[x][y];
    35 }
    36 int main()
    37 {
    38 //    int n,m;
    39     while(~scanf("%d%d",&n,&m),n>0&&m>0)
    40     {
    41         for(int i=1; i<=n; i++)
    42         {
    43             for(int j=1; j<=n; j++)
    44             {
    45                 scanf("%d",&a[i][j]);
    46             }
    47         }
    48         memset(dp,0,sizeof(dp));
    49         printf("%d
    ",dfs(1,1));
    50     }
    51     return 0;
    52 }
    View Code
  • 相关阅读:
    systemmap 使用记录
    reading code record
    吞吐问题
    debug cps 原因
    fopen的a+和rewind
    debug cps && perf debug
    tfo以及quic的阅读笔记
    ss 和netstat
    debug open files
    多核编程 local global
  • 原文地址:https://www.cnblogs.com/ITUPC/p/5294372.html
Copyright © 2011-2022 走看看