HDOJ 1078 Topic Footprints
Test instructions
N*n matrix, starting from (0,0), each point has a value, each can only horizontal or vertical to go to the maximum of K lattice, the total number of lines required is strictly monocytogenes, and the total and maximum.
Code:
1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <cstring>5 #defineMem (A, B) memset (A,b,sizeof (a))6 #defineForp (i,n) for (int i=0;i<n;i++)7 8 Const intMAXN = the;9 intN, K;Ten int_M[MAXN][MAXN]; One intDP[MAXN][MAXN]; A intdi[4][2] = {1,0,-1,0,0,1,0,-1}; - //direction - intDfsintXinty) { the intMaxx =0; - //record the current layer maximum value - intxx, yy, ans; - if(!Dp[x][y]) { + Forp (i,k) { -Forp (J,4){ +xx = x + di[j][0]* (i+1); Ayy = y + di[j][1]* (i+1); at if(XX >=0&& xx < n && yy >0&& yy < n && _m[xx][yy] >_m[x][y]) { -Ans = DFS (XX,YY);//value of Dp[xx][yy] - if(Ans >Maxx) -Maxx =ans; - } - } in } -Dp[x][y] = Maxx +_m[x][y]; to } +printf"%d%d%d\n", X,y,dp[x][y]); - returnDp[x][y]; the } * $ intMain () {Panax NotoginsengMem (_m,0); - while(~SCANF ("%d%d",&n,&k)) { the if(n = =-1&& k = =-1) + Break; A Forp (i,n) the Forp (j,n) +scanf"%d",&_m[i][j]); - //data read-in $MEM (DP,0); $ intsum = DFS (0,0); - //search starting from 0 o'clock -printf"%d\n", sum); the } -}
Memory Search Topics