Http://poj.org/problem? Id = 1958
The first question given to the algorithm.
The process is very clear. First, move n-k to B using four columns, and then move K to D using three columns, finally, move n-k to D using four columns. N-k are moved twice in total. We know the minimum number of steps for moving the three columns is 2 ^ n-1, the total number of moving steps is f [I-j] * 2 + T [J]. The equation f [I] = min (F [I], f [I-j] * 2 + T [J]).
Because we are more confident, we can directly use the large-sized materials, without using Majia. It would be dumbfounded once we handed in the paper, and re! Well, I really deserve it. Why is the array so small? Don't ask for money...
Code:
# Include <iostream>
# Define min (A, B) A> B? B:
Using namespace STD;
Int T [13], F [13];
Int main (){
Int I, J;
For (I = 0; I <= 12; I ++)
T [I] = (1 <I)-1;
For (I = 1; I <= 12; I ++ ){
F [I] = 100;
For (j = 1; j <= I; j ++)
F [I] = min (F [I], F [I-j] * 2 + T [J]);
Cout <F [I] <Endl;
}
Return 0;
}