Advertisement
erek1e

IOI '04 P4 - Phidias

Jul 14th, 2023
1,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  9.     int W, H; cin >> W >> H;
  10.     vector<vector<int>> minWasted(1+W, vector<int>(1+H));
  11.     for (int w = 0; w <= W; ++w) {
  12.         for (int h = 0; h <= H; ++h) minWasted[w][h] = w*h;
  13.     }
  14.  
  15.     int N; cin >> N;
  16.     while (N--) {
  17.         int w, h; cin >> w >> h;
  18.         minWasted[w][h] = 0;
  19.     }
  20.  
  21.     for (int w = 1; w <= W; ++w) {
  22.         for (int h = 1; h <= H; ++h) {
  23.             for (int w1 = 1; w1 < w; ++w1) { // vertical cut
  24.                 minWasted[w][h] = min(minWasted[w][h], minWasted[w1][h] + minWasted[w-w1][h]);
  25.             }
  26.             for (int h1 = 1; h1 < h; ++h1) { // horizontal cut
  27.                 minWasted[w][h] = min(minWasted[w][h], minWasted[w][h1] + minWasted[w][h-h1]);
  28.             }
  29.         }
  30.     }
  31.     cout << minWasted[W][H] << endl;
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement