Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Coins {
- public static int[] V;
- public static int S = 10000000;
- static int asdf = 0;
- public static void main(String[] args) {
- V = new int[100];
- for (int i = 0; i < 100; ++i)
- {
- V[i] = i * 2 + 1;
- }
- System.out.println(recurse(V.length - 1, 0));
- System.out.println(asdf);
- }
- public static int recurse(int i, int total) {
- int min = -1;
- int num = 0;
- if (i < 0) return (S - total == 0) ? 0 : -1;
- int N = (S - total) / V[i];
- for (int j = N; j >= 0 && j >= N - 1; j--) {
- int tmp = recurse(i - 1, total + V[i] * j);
- if (tmp >= 0 && (min == -1 || tmp < min)) {
- min = tmp;
- num = j;
- }
- ++asdf;
- }
- return min + num;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement