|
| 1 | +#include <iostream> |
| 2 | +#include <sstream> |
| 3 | +#include <vector> |
| 4 | +#include <algorithm> |
| 5 | +#include <set> |
| 6 | +#include <map> |
| 7 | +#include <queue> |
| 8 | +#include <cstring> |
| 9 | +#include <climits> |
| 10 | +#include <cstdio> |
| 11 | +using namespace std; |
| 12 | +typedef pair<int,int> pi; |
| 13 | +typedef set<int> si; |
| 14 | +typedef vector<int> vi; |
| 15 | +typedef vector<vi> vvi; |
| 16 | +typedef vector<string> vs; |
| 17 | +int dp[105][105]; |
| 18 | +int d = 0; |
| 19 | + |
| 20 | +int fun(int n, int k){ |
| 21 | + if(dp[n][k] != -1) return dp[n][k]; |
| 22 | + if(k == 0) return n; |
| 23 | + if(n == 1) return n; |
| 24 | + int minv = 1000000; |
| 25 | + d++; |
| 26 | + string s(d, ' '); |
| 27 | + // cout<<s<<n<<" "<<k<<endl; |
| 28 | + for(int a = 1; a < n; a++){ |
| 29 | + int b = n-a; |
| 30 | + for(int j = 0; j < k; j++) |
| 31 | + minv = min(minv, max(fun(a, k-1-j), fun(b, j)) + 1); |
| 32 | + } |
| 33 | + minv = min(minv, fun(n-1, k) + 1); |
| 34 | + dp[n][k] = minv; |
| 35 | + d--; |
| 36 | + string t(d, ' '); |
| 37 | + // cout<<t<<n<<" "<<k<<" "<<minv<<endl; |
| 38 | + return dp[n][k]; |
| 39 | +} |
| 40 | + |
| 41 | +class CartInSupermarketEasy{ |
| 42 | + public: |
| 43 | + int calc(int N, int K) { |
| 44 | + for(int i = 0; i <= 100; i++) |
| 45 | + for(int j = 0; j <= 100; j++) |
| 46 | + dp[i][j] = -1; |
| 47 | + return fun(N, K); |
| 48 | + } |
| 49 | + |
| 50 | +// BEGIN CUT HERE |
| 51 | + public: |
| 52 | + void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); } |
| 53 | + private: |
| 54 | + template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); } |
| 55 | + void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } } |
| 56 | + void test_case_0() { int Arg0 = 5; int Arg1 = 0; int Arg2 = 5; verify_case(0, Arg2, calc(Arg0, Arg1)); } |
| 57 | + void test_case_1() { int Arg0 = 5; int Arg1 = 2; int Arg2 = 4; verify_case(1, Arg2, calc(Arg0, Arg1)); } |
| 58 | + void test_case_2() { int Arg0 = 15; int Arg1 = 4; int Arg2 = 6; verify_case(2, Arg2, calc(Arg0, Arg1)); } |
| 59 | + void test_case_3() { int Arg0 = 7; int Arg1 = 100; int Arg2 = 4; verify_case(3, Arg2, calc(Arg0, Arg1)); } |
| 60 | + void test_case_4() { int Arg0 = 45; int Arg1 = 5; int Arg2 = 11; verify_case(4, Arg2, calc(Arg0, Arg1)); } |
| 61 | + void test_case_5() { int Arg0 = 100; int Arg1 = 100; int Arg2 = 8; verify_case(5, Arg2, calc(Arg0, Arg1)); } |
| 62 | + |
| 63 | +// END CUT HERE |
| 64 | + |
| 65 | +}; |
| 66 | + |
| 67 | +// BEGIN CUT HERE |
| 68 | +int main(){ |
| 69 | + |
| 70 | + CartInSupermarketEasy ___test; |
| 71 | + ___test.run_test(-1); |
| 72 | +} |
| 73 | +// END CUT HERE |
0 commit comments