Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1078
Test instructions: Every time can only walk sideways or vertical 1~k lattice, beg the most can eat cheese.
Code:
#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include <string>#include <functional>#include <iterator>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <set>#include <map>#include <list>#include <bitset>#include <sstream>#include <iomanip>#include <fstream>#include <iostream>#include <cmath>#include <cstring>#include <cstdio>#include <time.h>#include <ctype.h>#include <string.h>#include <assert.h>using namespace STD;intN, K;inta[ the][ the], dp[ the][ the];intdir[4][2] = { {1,0}, { -1,0}, {0,1}, {0, -1} };BOOLIS_OK (intXintY) {if(X <0|| X >= N | | Y <0|| Y >= N)return false;return true;}intResintXintY) {intsum =0, TMP =0;if(!dp[x][y]) { for(inti =1; I <= K; i++) { for(intj =0; J <4; J + +) {intxx = x + dir[j][0] * I;intyy = y + dir[j][1] * I;if(IS_OK (XX,YY) && a[xx][yy] > A[x][y]) {sum = res (xx, yy); TMP = MAX (tmp, SUM); }}} Dp[x][y] = tmp + a[x][y]; }returnDp[x][y];}intMain () { while(scanf("%d%d", &n,&k)! = EOF) {if(n = =-1&& k = =-1) Break; for(inti =0; I < n; i++) for(intj =0; J < N; J + +)scanf("%d", &a[i][j]);memset(DP,0,sizeof(DP));printf("%d\n", Res (0,0)); }return 0;}
Copyright NOTICE: Reprint please indicate the source.
HDU 1078 Fatmouse and Cheese "DP"