Tle in rectangle cutting ( cses problem set)

Revision en1, by JUDASS, 2023-05-01 17:31:15

This is problem link https://cses.fi/problemset/result/5982212/

include <bits/stdc++.h>

using namespace std; const int N=511; vector<vector> dp(N, vector(N, -1));

int find(int a, int b){ if(a == b) return 0; if(dp[a][b] != -1) return dp[a][b]; int A=1e9, B= 1e9; for(int x=1; x<a; ++x) { A=min(A, find(x,b)+find(a-x, b)+1); } for(int y=1; y<b; ++y) { B=min(B, find(a,y)+find(a,b-y)+1); } return dp[a][b]=min(A, B); } int main() { int a, b; cin>>a>>b; cout<<find(a, b);

return 0;

} My code is getting TLE in two cases while it's is under 10^4 iteration

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English JUDASS 2023-05-01 17:31:15 701 Initial revision (published)