Count ways to build street under given constraints | C ++ program of above approach ; Program to count ways ; Iterate from 2 to n ; Driver code ; Count Ways
#include <iostream> NEW_LINE using namespace std ; int countways ( long long n ) { long long A [ n + 1 ] ; A [ 0 ] = 1 ; A [ 1 ] = 3 ; A [ 2 ] = 7 ; for ( int i = 2 ; i <= n ; i ++ ) { A [ i ] = 2 * A [ i - 1 ] + A [ i - 2 ] ; } return A [ n ] ; } int main ( ) { int n = 5 ; cout << countways ( 5 ) << endl ; return 0 ; }