Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem: Bob's Sale
    primarykey
    data
    text
    <p><em>Note: this is an abstract rewording of a real-life problem regarding ordering records in a SWF file. A solution will help me improve an open-source application.</em></p> <p>Bob has a store, and wants to do a sale. His store carries a number of products, and he has a certain integer quantity of units of each product in stock. He also has a number of shelf-mounted price labels (as many as the number of products), with the prices already printed on them. He can place any price label on any product (unitary price for one item for his entire stock of that product), however some products have an additional restriction - any such product may not be cheaper than a certain other product.</p> <p>You must find how to arrange the price labels, such that the total cost of all of Bob's wares is as low as possible. The total cost is the sum of each product's assigned price label multiplied by the quantity of that product in stock.</p> <hr> <p>Given:</p> <ul> <li>N &ndash; the number of products and price labels</li> <li>S<sub><em>i</em></sub>, 0≤<em>i</em>&lt;N &ndash; the quantity in stock of product with index <em>i</em> (integer)</li> <li>P<sub><em>j</em></sub>, 0≤<em>j</em>&lt;N &ndash; the price on price label with index <em>j</em> (integer)</li> <li>K &ndash; the number of additional constraint pairs</li> <li>A<sub><em>k</em></sub>, B<sub><em>k</em></sub>, 0≤<em>k</em>&lt;K &ndash; product indices for the additional constraint <ul> <li>Any product index may appear at most once in B. Thus, the graph formed by this adjacency list is actually a set of directed trees.</li> </ul></li> </ul> <p>The program must find:</p> <ul> <li>M<sub><em>i</em></sub>, 0≤<em>i</em>&lt;N &ndash; mapping from product index to price label index (P<sub>M<sub><em>i</em></sub></sub> is price of product <em>i</em>)</li> </ul> <p>To satisfy the conditions:</p> <ol> <li>P<sub>M<sub>A<sub><em>k</em></sub></sub></sub> ≤ P<sub>M<sub>B<sub><em>k</em></sub></sub></sub>, for 0≤<em>k</em>&lt;K</li> <li>Σ(S<sub><em>i</em></sub> &times; P<sub>M<sub><em>i</em></sub></sub>) for 0≤<em>i</em>&lt;N is minimal</li> </ol> <hr> <p>Note that if not for the first condition, the solution would be simply sorting labels by price and products by quantity, and matching both directly.</p> <p>Typical values for input will be N,K&lt;10000. In the real-life problem, there are only several distinct price tags (1,2,3,4).</p> <hr> <p>Here's one example of why most simple solutions (including topological sort) won't work:</p> <p>You have 10 items with the quantities 1 through 10, and 10 price labels with the prices $1 through $10. There is one condition: the item with the quantity 10 must not be cheaper than the item with the quantity 1.</p> <p>The optimal solution is:</p> <pre><code>Price, $ 1 2 3 4 5 6 7 8 9 10 Qty 9 8 7 6 1 10 5 4 3 2 </code></pre> <p>with a total cost of $249. If you place the 1,10 pair near either extreme, the total cost will be higher.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload