Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- const int INF=1000000000;
- vector<vector<vector<int> > > mem;
- // (a,b]
- int calc(int a, int b, int k) {
- if (a+1==b) return 0;
- if (k<=0) return INF;
- int &ret=mem[a][b][k];
- if (ret!=-1) return ret;
- ret=INF;
- for (int i=a+1; i<b; ++i) {
- ret=min(ret,1+max(calc(a,i,k-1),calc(i,b,k)));
- }
- return ret;
- }
- int main() {
- mem=vector<vector<vector<int> > >(1000,vector<vector<int> >(1000,vector<int>(20,-1)));
- int k, n;
- for (; cin >> k >> n && k!=0;) {
- cout << calc(0,n+1,k) << endl;
- }
- }
Add Comment
Please, Sign In to add comment