C ++ implementation of above approach
#include <bits/stdc++.h> NEW_LINE using namespace std ; void countWays ( int a [ ] , int n ) { int i , j ; long suff [ n ] ; if ( a [ n - 1 ] == 2 ) suff [ n - 1 ] = 1 ;