Answers for "no of ways to get n from sum of 1 to k"

0

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);
    }
}
Posted by: Guest on August-10-2021

Code answers related to "no of ways to get n from sum of 1 to k"

Browse Popular Code Answers by Language