1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Collections.Generic;
static class Program {
    static void Main(String[] args) {
        hoge(int.Parse(args[0]), 0, 0, new int[int.Parse(args[1])]);
    }
    static void hoge(int n, int m, int sum, int[] items) {
        if (items.Length <= m) {
            if (n == sum) {
                Console.WriteLine(string.Join(", ", Array.ConvertAll<int, string>(items, 
                    delegate(int x) { return x.ToString(); })));
            }
        }
        else {
            for(int i = n - sum; 0 <= i ; i--) {
                items[m] = i;
                hoge(n, m + 1, sum + i, items);
            }
        }
    }
}