Count number of ways to reach a given score in a game | Returns number of ways to reach score n ; table [ i ] will store count of solutions for value i . Initialize all table values as 0 ; Base case ( If given value is 0 ) ; One by one consider given 3 moves and update the table [ ] values after the index greater than or equal to the value of the picked move ; Driver Code
< ? php function counts ( $ n ) { for ( $ j = 0 ; $ j < $ n + 1 ; $ j ++ ) $ table [ $ j ] = 0 ; $ table [ 0 ] = 1 ; for ( $ i = 3 ; $ i <= $ n ; $ i ++ ) $ table [ $ i ] += $ table [ $ i - 3 ] ; for ( $ i = 5 ; $ i <= $ n ; $ i ++ ) $ table [ $ i ] += $ table [ $ i - 5 ] ; for ( $ i = 10 ; $ i <= $ n ; $ i ++ ) $ table [ $ i ] += $ table [ $ i - 10 ] ; return $ table [ $ n ] ; } $ n = 20 ; echo " Count ▁ for ▁ " ; echo ( $ n ) ; echo ( " ▁ is ▁ " ) ; echo counts ( $ n ) ; $ n = 13 ; echo ( " STRNEWLINE " ) ; echo " Count ▁ for ▁ " ; echo ( $ n ) ; echo ( " ▁ is ▁ " ) ; echo counts ( $ n ) ; ? >