3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(-1); $bills = [2, 5, 20, 50]; $count = [3, 1, 4, 1]; $amount = 66; define('BIG_INT', 1000000000); $F = []; $F[0] = 0; $B[0] = [0, 0, 0, 0]; for ($m = 1; $m <= $amount; $m++) { $F[$m] = BIG_INT; foreach ($bills as $key) { $B[$m][] = 0; } for ($i = 0; $i < count($bills); $i++) { if ($m >= $bills[$i] && $F[$m - $bills[$i]] + 1 < $F[$m] && $count[$i] != 0) { if ($B[$m - $bills[$i]][$i] + 1 > $count[$i]) { continue; } else { $B[$m] = $B[$m - $bills[$i]]; $F[$m] = $F[$m - $bills[$i]] + 1; $B[$m][$i]++; } } } } if (array_sum($B[$amount]) > 0) { echo "Выдать сумму $amount можно так:\n"; foreach ($bills as $key => $value) { if ($B[$amount][$key] != 0) { $sum = $B[$amount][$key] * $value; echo "{$B[$amount][$key]} * $value = " . $sum . "\n"; } } } else { echo "Сумму нельзя выдать\n"; }
Output for git.master_jit, git.master, rfc.property-hooks
Выдать сумму 66 можно так: 3 * 2 = 6 3 * 20 = 60

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
270.87 ms | 405 KiB | 5 Q