Count number of ways to partition a set into k subsets | Java program to count number of partitions of a set with n elements into k subsets ; Returns count of different partitions of n elements in k subsets ; Base cases ; S ( n + 1 , k ) = k * S ( n , k ) + S ( n , k - 1 ) ; Driver program
import java . io . * ; class GFG { public static int countP ( int n , int k ) { if ( n == 0 k == 0 k > n ) return 0 ; if ( k == 1 k == n ) return 1 ; return ( k * countP ( n - 1 , k ) + countP ( n - 1 , k - 1 ) ) ; } public static void main ( String args [ ] ) { System . out . println ( countP ( 3 , 2 ) ) ; } }