Cheese, If You Please¶
- Title:
Cheese, If You Please - Judge / source:
Kattis - Original URL: https://open.kattis.com/problems/cheeseifyouplease
- Secondary topics:
Linear programming,Simplex,Resource allocation - Difficulty:
hard - Subtype:
Continuous blend-planning LP with one variable per product - Status:
solved - Solution file: cheeseifyouplease.cpp
Why Practice This¶
This is the cleanest in-repo anchor for the Simplex lane because the statement already wants one continuous linear program.
Nothing meaningful is gained by forcing it into:
- max flow
- DP
- greedy exchange
The right move is just:
- create one variable for each blend
- write one cheese-supply inequality per cheese type
- maximize total profit
- solve the LP directly
Recognition Cue¶
Reach for simplex when:
- the variables are "how much of each blend / product do we make?"
- every resource limit is linear
- the objective is linear profit
- fractional quantities are completely legal
The strongest smell is:
each product consumes fixed percentages of each ingredient,
and I want the best profit
Problem-Specific Transformation¶
Let:
x_j= pounds of blendj
For each cheese type i, the input gives:
- stock
w_i - percentage
p_ijof cheeseiused in one pound of blendj
So the resource constraint is:
The profit objective is:
where t_j is the profit per pound of blend j.
This is already the exact starter route:
Core Idea¶
The hard part is not a hidden combinatorial invariant. The hard part is trusting the modeling step and then calling the right solver.
1. One Variable Per Blend¶
Do not model decisions cheese-by-cheese.
The business decision is:
- how much of blend
jto produce
So the LP variables are the blend amounts themselves.
2. One Upper Bound Per Cheese Type¶
Every cheese shipment gives one constraint.
If a blend uses p_ij% of cheese i, then one pound of that blend consumes:
pounds of cheese i.
So the entire stock of cheese i becomes one linear inequality.
3. Profit Is Already Linear¶
Each pound of blend j adds profit t_j.
So the objective is simply:
No nonlinear interaction survives the transformation.
Implementation Plan¶
- read the stock vector
w - build an
n x mmatrixAwhere rowi, columnjisp_ij / 100 - let
b = w - let
c_j = t_j - run simplex for:
maximize c^T xAx <= bx >= 0- print the optimum rounded to the nearest cent
Complexity¶
The practical contest complexity is:
- one dense simplex solve on at most
50 x 50-style dimensions in the flagship task
That is exactly the scale where this generic route is still reasonable.
Main Traps¶
- forgetting to divide the percentages by
100 - modeling ingredient amounts as variables instead of blend amounts
- overthinking the problem into a graph or DP model
- assuming simplex gives an integer solution because the answer "looks like money"
Reopen Path¶
- Topic page: Simplex
- Practice ladder: Simplex ladder
- Starter template: simplex-max-ax-le-b.cpp
- Notebook refresher: Simplex hot sheet
- Compare points:
- Optimization And Duality
- Min-Cost Flow
Solutions¶
- Code: cheeseifyouplease.cpp