Class PE0031

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int[] coins
      Stores for every coin the count to fill 200 pence.
      private int count
      Counts the number of found combinations.
      private int[] used
      Stores for every coin how many are used in a combination.
    • Constructor Summary

      Constructors 
      Constructor Description
      PE0031()
      A simple constructor to set number and title.
    • Method Summary

      Modifier and Type Method Description
      private void check​(int level)
      Here the algorithm is implemented by checking every combination of coins.
      private int getSum()
      Calculates the sum of the combination in used array.
      void prepare()
      Initializes the coins and used arrays, and the count with 0.
      java.lang.String solve()
      This problem is solved by a recursive call of the check(int) method.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • coins

        private int[] coins
        Stores for every coin the count to fill 200 pence.
      • used

        private int[] used
        Stores for every coin how many are used in a combination.
      • count

        private int count
        Counts the number of found combinations.
    • Constructor Detail

      • PE0031

        public PE0031()
        A simple constructor to set number and title.
    • Method Detail

      • solve

        public java.lang.String solve()
        This problem is solved by a recursive call of the check(int) method. Here this method is called and the final count is returned.
        Returns:
        the count of all found combinations
      • check

        private void check​(int level)
        Here the algorithm is implemented by checking every combination of coins. If the sum of the current combination is less than 200 this method is called recursively for the next smaller coin.
        Parameters:
        level - the position in coins array
      • getSum

        private int getSum()
        Calculates the sum of the combination in used array.
        Returns:
        the sum of all products of elements in used and #coins array