Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tests2;
- import java.math.BigInteger;
- import java.util.ArrayList;
- public class Geldwechsel {
- static int betrag[] = { 2, 3, 5, 23, 32 };
- static int n = betrag.length;
- static ArrayList<Integer> fiboList = new ArrayList<>();
- //static long w[][];
- static BigInteger[][] w;
- static ArrayList<BigInteger> results= new ArrayList<>();
- /*
- static BigInteger w(int g, int i) {
- return g < 0 ? BigInteger.ZERO
- : i == 0 ? (g % betrag[0] == 0 ? BigInteger.ONE : BigInteger.ZERO)
- // : w[g][i] != 0 ? w[g][i] : (w[g][i] = w(g, i - 1) + w(g - betrag[i], i));
- : w[g][i].compareTo(BigInteger.ZERO) != 0 ? w[g][i]:(w[g][i] = w(g, i-1).add(w(g-betrag[i],i)));
- }
- */
- static BigInteger ww(int g, int i) {
- if (g<0) {
- return BigInteger.ZERO;
- } else if (i==0) {
- return (g%betrag[0] == 0 ? BigInteger.ONE : BigInteger.ZERO);
- } else {
- return w[g][i].compareTo(BigInteger.ZERO) != 0 ? w[g][i]:(w[g][i] = ww(g, i-1).add(ww(g-betrag[i],i)));
- }
- }
- static BigInteger results(int g, int i) {
- if (g<0) {
- results.add(BigInteger.ZERO);
- } else if (i==0) {
- results.add(g%betrag[0]==0?BigInteger.ONE:BigInteger.ZERO);
- } else {
- if (w[g][i].compareTo(BigInteger.ZERO) != 0) {
- results.add(w[g][i]);
- } else {
- results.add((w[g][i] = results(g, i-1).add(results(g-betrag[i],i))));
- }
- }
- if (g<0) {
- return BigInteger.ZERO;
- } else if (i==0) {
- return (g%betrag[0] == 0 ? BigInteger.ONE : BigInteger.ZERO);
- } else {
- return w[g][i].compareTo(BigInteger.ZERO) != 0 ? w[g][i]:(w[g][i] = ww(g, i-1).add(ww(g-betrag[i],i)));
- }
- }
- public static void fiboArray(int a, int b) {
- if (b == 102334155) {
- fiboList.add(b);
- } else {
- fiboList.add(b);
- fiboArray(b, a + b);
- }
- }
- public static void main(String[] args) {
- fiboList.add(1);
- fiboArray(1, 2);
- for (Integer g : fiboList) {
- w = new BigInteger[g+1][n];
- for (int i = 0; i<w.length; i++) {
- for (int j = 0; j<w[0].length;j++) {
- w[i][j]=BigInteger.ZERO;
- }
- }
- // w = new long[g + 1][n];
- System.out.println(g + "\t" + results(g, n - 1));
- }
- }
- }
Advertisement