ADDED SRM/TCO14-3B-U/1A.cpp Index: SRM/TCO14-3B-U/1A.cpp ================================================================== --- SRM/TCO14-3B-U/1A.cpp +++ SRM/TCO14-3B-U/1A.cpp @@ -0,0 +1,107 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef complex CMP; + +LL C(LL n, LL k) +{ + LL v = 1; + for(LL i=1; i<=k; ++i) + v = v*(n-i+1)/i; + return v; +} + +class IntoTheMatrix { public: + int takePills(int turns, int N) + { + for(int F=0 ;; ++F) + if(best(F,turns)>=N) + return F; + } + + map,LL> memo; + LL best(int F, int T) + { + if(T==0) + return 1; + + pair key(F,T); + if(memo.count(key)) + return memo[key]; + + LL sum = 0; + for(int f=0; f<=F; ++f) + sum += best(f, T-1)*C(F,f); + return memo[key] = sum; + } +}; + +// BEGIN CUT HERE +#include +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const int& Expected, const int& Received) { + bool ok = (Expected == Received); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, IntoTheMatrix().takePills(turns, N));} +int main(){ + +CASE(0) + int turns = 1; + int N = 1; + int _ = 0; +END +CASE(1) + int turns = 2; + int N = 10; + int _ = 3; +END +CASE(2) + int turns = 2; + int N = 1000; + int _ = 7; +END +CASE(3) + int turns = 10; + int N = 2; + int _ = 1; +END +CASE(4) + int turns = 4; + int N = 50; + int _ = 3; +END +CASE(5) + int turns = 1; + int N = 1000000; + int _ = -1; +END +CASE(6) + int turns = 10; + int N = 1000000; + int _ = -1; +END +} +// END CUT HERE