Count of subsets with sum equal to X |  ; Initializing the matrix ; Initializing the first value of matrix ; If the value is greater than the sum ; Driver Code
using System ; class GFG { static int subsetSum ( int [ ] a , int n , int sum ) { int [ , ] tab = new int [ n + 1 , sum + 1 ] ; tab [ 0 , 0 ] = 1 ; for ( int i = 1 ; i <= sum ; i ++ ) tab [ 0 , i ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) tab [ i , 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { if ( a [ i - 1 ] > j ) tab [ i , j ] = tab [ i - 1 , j ] ; else { tab [ i , j ] = tab [ i - 1 , j ] + tab [ i - 1 , j - a [ i - 1 ] ] ; } } } return tab [ n , sum ] ; } public static void Main ( String [ ] args ) { int n = 4 ; int [ ] a = { 3 , 3 , 3 , 3 } ; int sum = 6 ; Console . Write ( subsetSum ( a , n , sum ) ) ; } }