Http://acm.zju.edu.cn/onlinejudge/showProblem.do? Problemcode = 1428 I read the exercise question first. I thought it was graph theory and asked xsy to check the question .. In the end, you cannot give up. It was only after the end of the afternoon that it was originally a DP. Take the location of three vehicles as the status, J, K as the location of the car that is not moving, and I as the location of the current mobile car. DP [j, k, I] can be composed of DP [j, k, I + 1], DP [J, I, I + 1], DP [K, I, I + 1] Move once.
In addition, with a long memory, macro definition will never be used again in the future. The method for obtaining the maximum value of macro definition always fails and the cause cannot be found.
Code:
# Include <cstdio>
# Include <cstring>
# Include <algorithm>
Using namespace STD;
Int data [31] [31];
Int DP [31] [31] [31];
Int main (){
Int t, n, I, J, K;
Scanf ("% d", & T );
While (t --){
Memset (DP, 0, sizeof (DP ));
Scanf ("% d", & N );
For (I = 1; I <n; I ++)
For (j = I + 1; j <= N; j ++)
Scanf ("% d", & Data [I] [J]);
For (I = n-1; I> = 1; I --)
For (j = 1; j <= I; j ++)
For (k = 1; k <= I; k ++ ){
DP [J] [k] [I] = min (DP [J] [k] [I + 1] + data [I] [I + 1], DP [k] [I] [I + 1] + data [J] [I + 1]);
DP [J] [k] [I] = min (DP [J] [k] [I], DP [J] [I] [I + 1] + data [k] [I + 1]);
}
Printf ("% d \ n", DP [1] [1] [1]);
}
Return 0 ;}