Question: omitted
Analysis: memory-based search
Use DP [I] [J] to indicate that the number of I attacks is less than J.
Hdustm4
# Include <iostream> # Include <Algorithm> # Include <Stdio. h> # Include <Stdlib. h> # Include < String . H> Using Namespace STD; Const Int N =20 + 5 ; Const Int M = 600 + 10 ;__ Int64 f [N] ;__ int64 DP [N] [m]; Int S [ 3 ] = { 1 , 2 , 3 }; Void Init () {f [ 0 ] = 1 ; F [ 1 ] = 3 ; For ( Int I = 2 ; I <n; ++ I) f [I] = F [I- 1 ] * 3 ; }__ Int64 DFS ( Int Depth, Int Score ){ If (DP [depth] [score]! =- 1 ) Return DP [depth] [score]; If (Depth = 1 ){ Int Sum = 0 ; For ( Int I =0 ; I < 3 ; ++ I) If (Score> S [I]) ++ SUM; Return DP [depth] [score] = SUM;} _ int64 RET = 0 ; For ( Int I = 0 ; I <3 ; ++ I ){ If (Score> S [I]) RET + = DFS (depth- 1 , Score- S [I]);} Return DP [depth] [score] = RET ;} Int Main (){ Int A, B, T; Init (); While (Scanf ( " % D " , & A, & B, & T) = 3 ){ Int TOT = T/ 15 ; B + = TOT/ 2 ; Int N = tot-tot/ 2 ; // Number of times we can attack Int M = B-A +1 ; // We scored less than Team B If (M <= 0 ){ // Win Printf ( " % I64d \ n " , F [N]); Continue ;} If (M> N * 3 ) {Printf ( " 0 \ n " ); Continue ;} Memset (DP, - 1 , Sizeof (DP); printf ( " % I64d \ n " , F [N]- DFS (n, m ));} Return 0 ;}