Public class gametree {
/**
* Deduce the number of remaining balls. Who can win the final one,
* If one person is used for retrieval, we first take the result by default. If yes, true is returned. Otherwise, false is returned.
* @ Param X number of remaining balls
* @ Return
*/
Static Boolean F (int x ){
Int [] OP = {1, 3, 7, 8}; // there are only four cases for getting the ball each time.
For (INT I = 0; I <op. length; I ++ ){
If (x> = op [I]) {
If (f (x-op [I]) = false) return true; // game theory, the other party will lose, then we will win
}
}
Return false; // no matter how the other party goes, it is true, so we will lose
}
Public static void main (string [] ARGs ){
// Allocate adds efficiency using dynamic planning, stores computed sub-problems, and uses them directly in the future
System. Out. println (f (100 ));
}
}
Game tree and Dynamic Planning (the computed sub-problems are stored and used directly in the future)