Count all possible N | C # program to find absolute difference between the sum of all odd frequenct and even frequent elements in an array ; Function to find the number of vowel permutations possible ; To avoid the large output value ; Initialize 2D dp array ; Initialize dp [ 1 ] [ i ] as 1 since string of length 1 will consist of only one vowel in the string ; Directed graph using the adjacency matrix ; Iterate over the range [ 1 , N ] ; Traverse the directed graph ; Traversing the list ; Update dp [ i + 1 ] [ u ] ; Stores total count of permutations ; Return count of permutations ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int countVowelPermutation ( int n ) { int MOD = ( int ) ( 1e9 + 7 ) ; long [ , ] dp = new long [ n + 1 , 5 ] ; for ( int i = 0 ; i < 5 ; i ++ ) { dp [ 1 , i ] = 1 ; } List < List < int > > relation = new List < List < int > > ( ) ; relation . Add ( new List < int > { 1 } ) ; relation . Add ( new List < int > { 0 , 2 } ) ; relation . Add ( new List < int > { 0 , 1 , 3 , 4 } ) ; relation . Add ( new List < int > { 2 , 4 } ) ; relation . Add ( new List < int > { 0 } ) ; for ( int i = 1 ; i < n ; i ++ ) { for ( int u = 0 ; u < 5 ; u ++ ) { dp [ i + 1 , u ] = 0 ; foreach ( int v in relation [ u ] ) { dp [ i + 1 , u ] += dp [ i , v ] % MOD ; } } } long ans = 0 ; for ( int i = 0 ; i < 5 ; i ++ ) { ans = ( ans + dp [ n , i ] ) % MOD ; } return ( int ) ans ; } static void Main ( ) { int N = 2 ; Console . WriteLine ( countVowelPermutation ( N ) ) ; } }