- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle_Cutting.cpp
More file actions
Latest commit
29 lines (26 loc) · 548 Bytes
/
Copy pathRectangle_Cutting.cpp
File metadata and controls
29 lines (26 loc) · 548 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
#include<iostream>
#include<vector>
#include<climits>
#include<cstring>
usingnamespacestd;
int dp[501][501];
intsolve(int a, int b){
if(a==b){
return dp[a][b]=0;
}
if(dp[a][b]!=-1)return dp[a][b];
int ans=INT_MAX;
for(int i=1;i<a;i++){
ans=min(ans, solve(i, b)+1+solve(a-i, b));
}
for(int j=1;j<b;j++){
ans=min(ans, solve(a, j)+1+solve(a, b-j));
}
return dp[a][b]=ans;
}
intmain(){
int n, m;
cin>>n>>m;
memset(dp, -1, sizeof(dp));
cout<<solve(n, m)<<endl;
}