December 30, 2015

Euler Problem 31 ...

It's just a integer partition.
public class Test {
  static int count = 0;

  public static void main(String[] args) {
    partition(200, 200);
    System.out.println(count);
  }

  public static void partition(int n, int max) {
    if (n == 0) {
      count++;
      return;
    }

    for (int i = Math.min(max, n); i >= 1; i--) {
      if (i == 200 || i == 100 || i == 50 || i == 20 
          || i == 10 || i == 5 || i == 2 || i == 1)
        partition(n - i, i);
    }
  }

}

73682
Job Finished in 0.02 seconds
정수론에서 나오는 자연수 분할 문제 ..

No comments:

Post a Comment