Index: CheckList.pptx ================================================================== --- CheckList.pptx +++ CheckList.pptx cannot compute difference between binary files ADDED SRM/512-U/1A.cpp Index: SRM/512-U/1A.cpp ================================================================== --- SRM/512-U/1A.cpp +++ SRM/512-U/1A.cpp @@ -0,0 +1,116 @@ +#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; + +class MysteriousRestaurant { public: + int maxDays(vector prices, int budget) + { + for(int D=prices.size(); D>=0; --D) + if( ok(D, prices, budget) ) + return D; + return 0; + } + + bool ok(int D, const vector& prices, int budget) + { + int M = prices[0].size(); + + vector< vector > p(7, vector(M)); + for(int i=0; i +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(_, MysteriousRestaurant().maxDays(prices, budget));} +int main(){ + +CASE(0) + string prices_[] = {"26", "14", "72", "39", "32", "85", "06"}; + vector prices(prices_, prices_+sizeof(prices_)/sizeof(*prices_)); + int budget = 13; + int _ = 5; +END +CASE(1) + string prices_[] = {"26", "14", "72", "39", "32", "85", "06", "91"}; + vector prices(prices_, prices_+sizeof(prices_)/sizeof(*prices_)); + int budget = 20; + int _ = 8; +END +CASE(2) + string prices_[] = {"SRM", "512"}; + vector prices(prices_, prices_+sizeof(prices_)/sizeof(*prices_)); + int budget = 4; + int _ = 0; +END +CASE(3) + string prices_[] = {"Dear", "Code", "rsHa", "veFu", "nInT", "heCh", "alle", "ngeP", "hase", "andb", "ecar", "eful"}; + vector prices(prices_, prices_+sizeof(prices_)/sizeof(*prices_)); + int budget = 256; + int _ = 10; +END +/* +CASE(4) + string prices_[] = ; + vector prices(prices_, prices_+sizeof(prices_)/sizeof(*prices_)); + int budget = ; + int _ = ; +END +CASE(5) + string prices_[] = ; + vector prices(prices_, prices_+sizeof(prices_)/sizeof(*prices_)); + int budget = ; + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/512-U/1B-U.cpp Index: SRM/512-U/1B-U.cpp ================================================================== --- SRM/512-U/1B-U.cpp +++ SRM/512-U/1B-U.cpp @@ -0,0 +1,139 @@ +#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; + +class SubFibonacci { public: + vector fib; + + int maxElements(vector S) + { + fib.assign(100, 0); + fib[0] = 0; + fib[1] = 1; + for(size_t k=2; k& S, int s, int e) + { + set all(S.begin()+s, S.begin()+e); + int result = min(2, e-s); + for(int i=s; i +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(_, SubFibonacci().maxElements(S));} +int main(){ + +CASE(0) + int S_[] = {8, 1, 20, 3, 10}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 5; +END +CASE(1) + int S_[] = {19, 47, 50, 58, 77, 99}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 4; +END +CASE(2) + int S_[] = {512}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 1; +END +CASE(3) + int S_[] = {3, 5, 7, 10, 13, 15, 20, 90}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 7; +END +CASE(4) + int S_[] = {1, 2, 3, 5, 8, 13, 21, 34, 55, 89}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 10; +END +CASE(5) + int S_[] = {1}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 1; +END +CASE(6) + int S_[] = {1,2}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 2; +END +CASE(7) + int S_[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 11; +END +CASE(8) + int S_[] = {1,3,4,5,61,97,157}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 6; +END +CASE(8) + int S_[] = {2,4,6,10,999,1000}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 6; +END +} +// END CUT HERE ADDED SRM/512-U/1C-U.cpp Index: SRM/512-U/1C-U.cpp ================================================================== --- SRM/512-U/1C-U.cpp +++ SRM/512-U/1C-U.cpp @@ -0,0 +1,142 @@ +#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; + +static const int MODVAL = 1000000007; +LL C[201][201]; + +class PickAndDelete { public: + int count(vector S_) + { + init_C(); + vector S; + { + string s = accumulate(S_.begin(), S_.end(), string("")); + stringstream ss(s); + for(int v; ss>>v; ) + S.push_back(v); + } + sort(S.begin(), S.end()); + return solve(S); + } + + void init_C() + { + for(int n=0; n<=200; ++n) + for(int k=0; k<=n; ++k) + if( k==0 || k==n ) + C[n][k] = 1; + else + C[n][k] = (C[n-1][k-1] + C[n-1][k]) % MODVAL; + } + + int solve(const vector& S) + { + map, LL> dp; + dp[multiset()] = 1; + + for(int i=0; i, LL> dp2; + for(map,LL>::iterator it=dp.begin(); it!=dp.end(); ++it) + { + const multiset& sig = it->first; + if( sig.size() < next ) { + multiset new_sig = sig; + new_sig.insert(1); + (dp2[new_sig] += it->second*(next-sig.size())) %= MODVAL; + } + for(multiset::const_iterator jt=sig.begin(); jt!=sig.end(); ++jt) + { + multiset new_sig = sig; + new_sig.erase(*jt); + new_sig.insert(*jt+1); + (dp2[new_sig] += it->second) %= MODVAL; + } + } + dp.swap(dp2); + } + + LL sum = 0; + for(map,LL>::iterator it=dp.begin(); it!=dp.end(); ++it) + { + LL n = it->second; + int tt = S.size(); + for(multiset::const_iterator jt=it->first.begin(); jt!=it->first.end(); ++jt) { + (n *= C[tt][*jt]) %= MODVAL; + tt -= *jt; + } + sum += n; + } + return int(sum % MODVAL); + } +}; + +// 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(_, PickAndDelete().count(S));} +int main(){ + +CASE(0) + string S_[] = {"1 2"}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 3; +END +CASE(1) + string S_[] = {"2 2 2 2 2 2 2 2 2"}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 512; +END +CASE(2) + string S_[] = {"5", " 1 ", "2"}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 34; +END +CASE(3) + string S_[] = {"3 ", "14159 265", "3589 7", " 932"}; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = 353127147; +END +/* +CASE(4) + string S_[] = ; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = ; +END +CASE(5) + string S_[] = ; + vector S(S_, S_+sizeof(S_)/sizeof(*S_)); + int _ = ; +END +*/ +} +// END CUT HERE