ADDED SRM/TCO19-3A-U/1A.cpp Index: SRM/TCO19-3A-U/1A.cpp ================================================================== --- SRM/TCO19-3A-U/1A.cpp +++ SRM/TCO19-3A-U/1A.cpp @@ -0,0 +1,250 @@ +#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 unsigned MODVAL = 1000000007; +struct mint +{ + unsigned val; + mint() :val(0) {} + mint(int x) :val(x%MODVAL) {} + mint(unsigned x) :val(x%MODVAL) {} + mint(LL x) :val(x%MODVAL) {} +}; +mint& operator+=(mint& x, mint y) { return x = x.val + y.val; } +mint& operator-=(mint& x, mint y) { return x = x.val - y.val + MODVAL; } +mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } +mint operator+(mint x, mint y) { return x += y; } +mint operator-(mint x, mint y) { return x -= y; } +mint operator*(mint x, mint y) { return x *= y; } + +mint POW(mint x, LL e) { mint v = 1; for (; e; x *= x, e >>= 1) if (e & 1) v *= x; return v; } +mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL - 2); } +mint operator/(mint x, mint y) { return x /= y; } + +vector FAC_(1, 1); +mint FAC(LL n) { while (FAC_.size() <= n) FAC_.push_back(FAC_.back()*LL(FAC_.size())); return FAC_[n]; } + +vector< vector > CP_; +mint C(int n, int k) { + while (CP_.size() <= n) { + int nn = CP_.size(); + CP_.push_back(vector(nn + 1, 1)); + for (int kk = 1; kk > SP_; +mint S(int n, int k) { + while (SP_.size() <= n) { + int nn = SP_.size(); + SP_.push_back(vector(nn + 1, 1)); + for (int kk = 2; kk a, int k) + { + const int f = int(a.size()); + const int nc = accumulate(a.begin(), a.end(), 0); + mint ans = 0; + for (int parentTable = 1; parentTable <= min(f, k); ++parentTable) + ans += POW(k - parentTable + 1, nc) * C(k, parentTable) * countParentWays(f, parentTable); + return ans.val; + } + + // |p| people to |t| tables + mint countParentWays(int p, int t) + { + return S(p, t) * FAC(t); + } +}; + +// 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(_, FamilySeatingArrangement().countWays(a, k));} +int main(){ + +CASE(0) + int a_[] = {2,1} ; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int k = 2; + int _ = 18; +END +CASE(1) + int a_[] = {2,1}; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int k = 3; + int _ = 129; +END +CASE(2) + int a_[] = {2,1}; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int k = 1000; + int _ = 989021965; +END +CASE(3) + int a_[] = {1,1,1,1,1,1,1,1,1,1,1,1}; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int k = 8; + int _ = 604306839; +END +CASE(4) + int a_[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20} ; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int k = 211; + int _ = 775937801; +END +CASE(5) +int a_[] = { 1 }; +vector a(a_, a_ + sizeof(a_) / sizeof(*a_)); +int k = 2; +int _ = 4; +END +CASE(6) +int a_[] = { 1 }; +vector a(a_, a_ + sizeof(a_) / sizeof(*a_)); +int k = 1; +int _ = 1; +END +CASE(7) +int a_[] = { +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000, +1000,1000,1000,1000,1000,1000,1000,1000,1000,1000 }; + vector a(a_, a_+sizeof(a_)/sizeof(*a_)); + int k = 1000; + int _ = -1; +END +} +// END CUT HERE