Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2686
Multi-process DP, first heard of yesterday...
The question is to find two paths from (1, 1) to (n, n) so that the weights are the largest and the nodes do not overlap.
Let the two processes run at the same time, with K enumeration steps. If X1 = X2 | Y1 = Y2, skip this step. The state transition equation is obtained:
DP (K, X1, Y1, X2, Y2) = max (dp (K-1, x1-1, Y1, x2-1, Y2), DP (K-1, x1-1, Y1, X2, y2-1), DP (K-1, X1, y1-1, x2-1, Y2), DP (K-1, X1, y1-1, X2, y2-1 ))
+ Data (x1, Y1) + data (X2, Y2 );
Since it can only go right or down, the coordinates must be x + y = K. In this way, the dimension can be reduced to three dimensions, and the equation is:
DP (K, x1, x2) = max (dp (K-1, x1, x2), DP (K-1, x1-1, X2), DP (K-1, X1, x2-1 ), DP (K-1, x1-1, x2-1) + data (x1, k-x1) + data (X2, k-x2 );
Code:
# Include <cstdio>
# Include <cstring>
# Define max (A, B) A> B? A: B
Int data [31] [31], DP [62] [31] [31];
Int max (int A, int B, int C, int d ){
A = max (A, B );
C = max (c, d );
A = max (a, c );
Return;
}
Int main (){
Int N, I, J, K;
While (~ Scanf ("% d", & N )){
For (I = 0; I <n; I ++)
For (j = 0; j <n; j ++)
Scanf ("% d", & Data [I] [J]);
Memset (DP, 0, sizeof (DP ));
For (k = 1; k <2 * N-2; k ++ ){
For (I = 0; I <= K; I ++ ){
For (j = 0; j <= K; j ++ ){
If (I = j | I> = n | j> = N) continue;
DP [k] [I] [J] = max (DP [k-1] [I] [J], DP [k-1] [I-1] [J], DP [k-1] [I] [J-1], DP [k-1] [I-1] [J-1]);
DP [k] [I] [J] + = data [I] [k-I] + data [J] [k-J];
}
}
}
DP [k] [n-1] [n-1] = max (DP [k-1] [N-2] [n-1], DP [k-1] [n-1] [N-2]) + data [n-1] [n-1] + data [0] [0];
Printf ("% d \ n", DP [k] [n-1] [n-1]);
}
Return 0 ;}