日期:2014-05-20 浏览次数:20752 次
import java.util.*; public class Test { public static void main(String[] args) throws Throwable { int n = 200; int[] blank = new int[10]; Arrays.fill(blank, 1); blank[blank.length-1] += (200-blank.length); int sum = 0; long cnt = 1; while (true) { sum = 0; for (int i=0; i<blank.length; i++) { sum += blank[i]; } if (sum == 200) { System.out.printf("method-%d: %s\r\n", cnt++, Arrays.toString(blank)); } blank[blank.length-1]++; for (int i=blank.length-1; i>0; i--) { if (blank[i] > 200-blank.length+1) { blank[i] = 1; blank[i-1]++; } else { break; } } if (blank[0] == 200-blank.length+1) { System.out.printf("method-%d: %s\r\n", cnt++, Arrays.toString(blank)); break; } } } }