Count ways to build street under given constraints | Java program of above approach ; Program to count ways ; Iterate from 2 to n ; Driver code ; Count Ways
import java . io . * ; class GFG { static int countways ( int n ) { int [ ] A = new int [ 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 ] ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( countways ( 5 ) ) ; } }