Guest User

Untitled

a guest
Jul 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. const int INF=1000000000;
  7.  
  8. vector<vector<vector<int> > > mem;
  9.  
  10. // (a,b]
  11. int calc(int a, int b, int k) {
  12. if (a+1==b) return 0;
  13. if (k<=0) return INF;
  14. int &ret=mem[a][b][k];
  15. if (ret!=-1) return ret;
  16. ret=INF;
  17. for (int i=a+1; i<b; ++i) {
  18. ret=min(ret,1+max(calc(a,i,k-1),calc(i,b,k)));
  19. }
  20. return ret;
  21. }
  22.  
  23. int main() {
  24. mem=vector<vector<vector<int> > >(1000,vector<vector<int> >(1000,vector<int>(20,-1)));
  25. int k, n;
  26. for (; cin >> k >> n && k!=0;) {
  27. cout << calc(0,n+1,k) << endl;
  28. }
  29. }
Add Comment
Please, Sign In to add comment