// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class CombiSplit {
    public static void split(int maxlen, int[] lens, int[] n, int curlen, int start) {
        if(lens[0] > maxlen - curlen) {
            for(int i = 0; i < n.length; i++) {
                System.out.print(" " + n[i]);
            }
            System.out.println();
        } else {
            int i = start;
            while(i < lens.length && lens[i] <= maxlen - curlen) {
                n[i]++;
                split(maxlen, lens, n, curlen + lens[i], i);
                n[i]--;
                i++;
            }
        }
    }
    public static void split(int maxlen, int[] lens) {
        int n[] = new int[lens.length];
        split(maxlen, lens, n, 0, 0);
    }
    public static void main(String[] args) {
        split(300, new int[] { 40, 80, 110, 130, 150, 180, 210 });
    }
}
