no of ways to get n from sum of 1 to k
public class IntegerPartition {
static int count=0;
public static void partition(int n, int max) {
if (n == 0) {
count++;
return;
}
for (int i = Math.min(max, n); i >= 1; i--) {
partition(n - i, i);
}
}
public static void main(String[] args) {
partition(5,3);
System.out.println("Count: "+count);
}
}