たとえば、n が 4 の場合、n1 + n2 = 4 です。n、n1、n2 >=0
出力は
[4, 0] [0, 4] [1, 3] [2, 2] [3, 1]
私は試した。
public static void partition(int n, int x, int y) throws Exception{
int n1, n2;
n1 = x;
n2 = y;
System.out.println(n1 + " : " + n2);
x = x - 1;
y = y + 1;
if ( x >= 0) {
TestMethods.partition(n, x, y);
} else {
return;
}
}
上記のメソッドを TestMethods.partition(4, 4, 0); として呼び出しています。
この方法をより効率的にするために、この方法にどのような改善を加えることができるかを確認したいと思います。