Cappuccino90

Untitled

Oct 25th, 2015
163
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. package tests2;
  2.  
  3. import java.math.BigInteger;
  4. import java.util.ArrayList;
  5.  
  6. public class Geldwechsel {
  7.  
  8.     static int betrag[] = { 2, 3, 5, 23, 32 };
  9.     static int n = betrag.length;
  10.  
  11.     static ArrayList<Integer> fiboList = new ArrayList<>();
  12.  
  13.     //static long w[][];
  14.    
  15.     static BigInteger[][] w;
  16.     static ArrayList<BigInteger> results= new ArrayList<>();
  17.    
  18.    
  19. /*
  20.     static BigInteger w(int g, int i) {
  21.         return g < 0 ? BigInteger.ZERO
  22.                 : i == 0 ? (g % betrag[0] == 0 ? BigInteger.ONE : BigInteger.ZERO)
  23.                        // : w[g][i] != 0 ? w[g][i] : (w[g][i] = w(g, i - 1) + w(g - betrag[i], i));
  24.                         : w[g][i].compareTo(BigInteger.ZERO) != 0 ? w[g][i]:(w[g][i] = w(g, i-1).add(w(g-betrag[i],i)));
  25.     }
  26.   */  
  27.    
  28.     static BigInteger ww(int g, int i) {
  29.         if (g<0) {
  30.             return BigInteger.ZERO;
  31.         } else if (i==0) {
  32.             return (g%betrag[0] == 0 ? BigInteger.ONE : BigInteger.ZERO);
  33.         } else {
  34.             return w[g][i].compareTo(BigInteger.ZERO) != 0 ? w[g][i]:(w[g][i] = ww(g, i-1).add(ww(g-betrag[i],i)));
  35.         }
  36.     }
  37.    
  38.     static BigInteger results(int g, int i) {
  39.         if (g<0) {
  40.             results.add(BigInteger.ZERO);
  41.         } else if (i==0) {
  42.             results.add(g%betrag[0]==0?BigInteger.ONE:BigInteger.ZERO);
  43.         } else {
  44.             if (w[g][i].compareTo(BigInteger.ZERO) != 0) {
  45.                 results.add(w[g][i]);
  46.             } else {
  47.                 results.add((w[g][i] = results(g, i-1).add(results(g-betrag[i],i))));  
  48.             }
  49.         }
  50.        
  51.        
  52.        
  53.        
  54.        
  55.        
  56.         if (g<0) {
  57.             return BigInteger.ZERO;
  58.         } else if (i==0) {
  59.             return (g%betrag[0] == 0 ? BigInteger.ONE : BigInteger.ZERO);
  60.         } else {
  61.             return w[g][i].compareTo(BigInteger.ZERO) != 0 ? w[g][i]:(w[g][i] = ww(g, i-1).add(ww(g-betrag[i],i)));
  62.         }
  63.        
  64.        
  65.        
  66.        
  67.        
  68.     }
  69.    
  70.    
  71.    
  72.    
  73.     public static void fiboArray(int a, int b) {
  74.         if (b == 102334155) {
  75.             fiboList.add(b);
  76.         } else {
  77.             fiboList.add(b);
  78.             fiboArray(b, a + b);
  79.         }
  80.     }
  81.  
  82.     public static void main(String[] args) {
  83.         fiboList.add(1);
  84.         fiboArray(1, 2);
  85.  
  86.    
  87.        
  88.        
  89.         for (Integer g : fiboList) {
  90.            
  91.             w = new BigInteger[g+1][n];
  92.            
  93.             for (int i = 0; i<w.length; i++) {
  94.                 for (int j = 0; j<w[0].length;j++) {
  95.                     w[i][j]=BigInteger.ZERO;
  96.                 }
  97.             }
  98.            
  99.            // w = new long[g + 1][n];
  100.             System.out.println(g + "\t" + results(g, n - 1));
  101.         }
  102.     }
  103. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment