private void calculateCombinations(int[] combination) { do { int k = check(combination, rest); if ((k > 0) && (k < currentCnt)) { currentCnt = k; currentCombination = new int[combination.Length]; for (int j = 0; j < combination.Length; j++) { currentCombination[j] = combination[j]; } } } while (Perm.getNextPerm(ref combination)); }
/*Сколько монет каждого номинала надо отдать*/ public int[] restCoins() { int sellerCoinsCnt = 0; for (int j = 0; j < cashBox.Length; j++) { sellerCoinsCnt += cashBox[j]; } data = new int[sellerCoinsCnt]; int k = 0; for (int i = 0; i < cashBox.Length; i++) { for (int j = 0; j < cashBox[i]; j++) { data[k] = listCoins[i]; k++; } } k = 0; currentCnt = sellerCoinsCnt; int[] firstCombination = Perm.getFirstPerm(sellerCoinsCnt); calculateCombinations(firstCombination); int[] result = new int[data.Length]; for (int l = 0; l < data.Length; l++) { result[l] = data[currentCombination[l]]; } return(result); /*int[] result = new int[8]; * * int i = 0; * * while (!found || (i<sellerCoinsCnt)) * { * result = recRest(++i, result, 0); * } * if (!found) * { * throw new Exception(); * }*/ }