Advertisement
ivnikkk

Untitled

Mar 16th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define debug(l) cerr<<" smotri huinyi : "<<#l<<' '<<l<<'\n';
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5. #define all(a) a.begin(), a.end()
  6. typedef long long ll;
  7. typedef long double ld;
  8. signed main() {
  9. #ifdef _DEBUG
  10.     freopen("input.txt", "r", stdin);
  11.     freopen("output.txt", "w", stdout);
  12. #endif
  13.     ios_base::sync_with_stdio(false);
  14.     cin.tie(nullptr);
  15.     srand(time(NULL));
  16.     ll n, w1, h1;
  17.     cin >> w1 >> h1 >> n;
  18.     vector<ll> w(n), h(n);
  19.     vector<vector<ll>> dp(w1 + 1, vector<ll>(h1 + 1,0));
  20.     for (ll i = 0; i < n; i++) {
  21.         cin >> w[i] >> h[i];
  22.         dp[w[i]][h[i]] = 1;
  23.     }
  24.     for (ll i = 1; i <= w1; i++) {
  25.         for (ll j = 1; j <= h1; j++) {
  26.             for (ll k = 1; k <= i; k++) {
  27.                 dp[i][j] = max(dp[k][j] + dp[i-k][j], dp[i][j]);
  28.             }
  29.             for (ll k = 1; k <= j; k++) {
  30.                 dp[i][j] = max(dp[i][k] + dp[i][j - k], dp[i][j]);
  31.             }
  32.         }
  33.     }
  34.     cout << dp[w1][h1] << '\n';
  35.  
  36.    
  37. }
  38.  
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement