Test instructions: Give a matrix, (max) to (N,n) two paths (not intersect), the maximum value to be obtained
Data range: 2 <= n <= 30, number < 100 on matrix
Ideas: Remember in the Kuangbin the most short-circuit topic there is a requirement of the same question, when it is not written out, check the solution is the biggest flow????
Then asked the big guy, said the problem can also be network flow to do, but ... And then I learned about this thing called multi-threaded DP.
Multithreading..???? It's not the C-language thing. It? It looks like it's going to work. Orz
In fact, this refers to the DP array in two points of the state can go out of how much of the maximum value, walking time not to a point on the line, with the memory of the search to write very convenient very good understanding is similar to the explosion search
With recursion can also save a dimension of space, set is currently the K step, each time from k-1 transfer, and then constant x+y==k can only set three-dimensional state
Self-written is memory, after all n only 30
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 6 Const intMX = *;7 intA[MX][MX], dp[mx][mx][mx][mx], N;8 intDr[] = {1,0,1,0};9 intDc[] = {0,1,0,1};Ten intDu[] = {1,1,0,0}; One intDv[] = {0,0,1,1}; A - intDfsintXintYintUintv) { - if(A[x][y] = =-1|| A[U][V] = =-1)return 0; the if(X+y = =2*n)returnA[n][n]; - if(Dp[x][y][u][v]! =-1)returnDp[x][y][u][v]; - if(x = = U && y = = v && x+y >2)return 0; - intAns =0; + for(inti =0; I <4; i++){ - intDX = x +Dr[i]; + intDy = y +Dc[i]; A intr = U +Du[i]; at intc = v +Dv[i]; -Ans =max (ans, dfs (dx, DY, R, c)); - } - returnDP[X][Y][U][V] = ans+a[x][y]+A[u][v]; - } - in intMain () { - while(SCANF ("%d", &n) = =1){ toMemset (DP,-1,sizeofDP); +Memset (A,-1,sizeofa); - for(inti =1; I <= N; i++) the for(intj =1; J <= N; J + +) *scanf"%d", &a[i][j]); $printf"%d\n", DFS (1,1,1,1)-a[1][1]);Panax Notoginseng } - return 0; the}
HDU-2686 Matrix (multi-threaded DP?) ) 2017 Winter Camp