Link: HDU 4972 A Simple Dynamic Programming Problem
The two teams are playing basketball. Each time a score is played, the score card is updated. The counting method of the score card is to record the absolute value of the score difference between the two teams, the score for each goal may be 1, 2, or 3. Given the scoring situation in the competition, I would like to ask how many situations the last score has.
Solution: Classification discussion:
- When the adjacent score is 1-2 or 2-1, there are two possible scores.
- If the adjacent score difference is greater than 3 or equal and not equal to 1, the input is invalid.
- In other cases, no new score is generated.
- When the last score difference is 0, no one wins or loses.
#Include<Cstdio> #Include<Cstring> #Include<Algorithm> Using Namespace STD ; Const Int Maxn = 1e5 + 5 ; Int N, a [maxn]; Int Solve (){ Int CNT = 1 ; For ( Int I = 1 ; I <= N; I ++ ){If (A [I] = 1 & A [I- 1 ] = 2 ) CNT ++; Else If (A [I] = 2 & A [I- 1 ] = 1 ) CNT ++;Else If (A [I]-A [I- 1 ]> 3 | A [I- 1 ]-A [I]> 3 ) Return 0 ; Else If (A [I] = A [I-1 ] & A [I]! = 1 ) Return 0 ;} If (A [n] = 0 ) Return CNT; Else Return CNT * 2 ;} Int Main (){ Int CAS; Scanf ( "% D" , & CAS ); For ( Int Kcas = 1 ; Kcas <= CAS; kcas ++ ){ Scanf ( "% D" , & N );For ( Int I = 1 ; I <= N; I ++) Scanf ( "% D" , & A [I]); Printf ( "Case # % d: % d \ n" , Kcas, solve ());} Return 0 ;}