Esempio n. 1
0
            }
        }
    }
    public function sum_up($numbers, $target)
    {
        //echo "[In SumSet.sum_up(Array[". implode($numbers, ",") . "], " . $target . ")]</br></br>";
        $result = array();
        print_r($this->sum_up_recursive($numbers, $target, $result, 1));
        exit;
    }
    public function main()
    {
        //echo "[In SumSet.main()]</br></br>";
        $target = 770;
        $this->copuon($target);
    }
    public function copuon($target)
    {
        $numbers = array();
        $set = array(100, 50, 30, 20);
        foreach ($set as $x) {
            $count = floor($target / $x);
            for ($i = 0; $i < $count; $i++) {
                $numbers[] = $x;
            }
        }
        $this->sum_up($numbers, $target);
    }
}
$obj = new SumSet();
$obj->main();
Esempio n. 2
0
     * 
     * @param type $target
     * @return int
     */
    public function getPossiblePacket($target)
    {
        $total_packet = array();
        $set = array(100, 50, 30, 20);
        foreach ($set as $set_item) {
            $count = floor($target / $set_item);
            for ($i = 1; $i <= $count; $i++) {
                $total_packet[] = $set_item;
            }
        }
        return $total_packet;
    }
    /**
     * 
     * @param type $amount
     * @param type $is_choice
     */
    public function calculatePacket($amount, $is_choice)
    {
        $target_res = $this->getMinimumMaximumTarget($amount, $is_choice);
        $packet_arr = $this->getPossiblePacket($target_res);
        $packet_res = $this->sum_up($packet_arr, $target_res);
        print_r("sum(" . implode($packet_res, ",") . ")=" . $target_res . "</br></br>");
    }
}
$obj = new SumSet();
$obj->calculatePacket(475, 0);