-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangleCutting.cpp
More file actions
43 lines (36 loc) · 920 Bytes
/
RectangleCutting.cpp
File metadata and controls
43 lines (36 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//Rectangle Cutting - https://cses.fi/problemset/task/1744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int inf = 1e9 + 2;
void solve() {
int a, b;
cin >> a >> b;
vector<vector<int>> dp(a + 1, vector<int>(b + 1, inf));
for (int i = 0; i <= min(a, b); i++) {
dp[i][i] = 0;
}
for (int i = 1; i <= a; i++) {
for (int j = 1; j <= b; j++) {
for (int k = 1; k < i; k++) {
dp[i][j] = min(dp[i][j], 1 + dp[k][j] + dp[i - k][j]);
}
for (int k = 1; k < j; k++) {
dp[i][j] = min(dp[i][j], 1 + dp[i][k] + dp[i][j - k]);
}
}
}
cout << dp[a][b] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}