Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(l) cerr<<" smotri huinyi : "<<#l<<' '<<l<<'\n';
- #include "bits/stdc++.h"
- using namespace std;
- #define all(a) a.begin(), a.end()
- typedef long long ll;
- typedef long double ld;
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- srand(time(NULL));
- ll n, w1, h1;
- cin >> w1 >> h1 >> n;
- vector<ll> w(n), h(n);
- vector<vector<ll>> dp(w1 + 1, vector<ll>(h1 + 1,0));
- for (ll i = 0; i < n; i++) {
- cin >> w[i] >> h[i];
- dp[w[i]][h[i]] = 1;
- }
- for (ll i = 1; i <= w1; i++) {
- for (ll j = 1; j <= h1; j++) {
- for (ll k = 1; k <= i; k++) {
- dp[i][j] = max(dp[k][j] + dp[i-k][j], dp[i][j]);
- }
- for (ll k = 1; k <= j; k++) {
- dp[i][j] = max(dp[i][k] + dp[i][j - k], dp[i][j]);
- }
- }
- }
- cout << dp[w1][h1] << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement