e3362a9488 2014-05-10 kinaba: #include <iostream> e3362a9488 2014-05-10 kinaba: #include <sstream> e3362a9488 2014-05-10 kinaba: #include <iomanip> e3362a9488 2014-05-10 kinaba: #include <vector> e3362a9488 2014-05-10 kinaba: #include <string> e3362a9488 2014-05-10 kinaba: #include <map> e3362a9488 2014-05-10 kinaba: #include <set> e3362a9488 2014-05-10 kinaba: #include <algorithm> e3362a9488 2014-05-10 kinaba: #include <numeric> e3362a9488 2014-05-10 kinaba: #include <iterator> e3362a9488 2014-05-10 kinaba: #include <functional> e3362a9488 2014-05-10 kinaba: #include <complex> e3362a9488 2014-05-10 kinaba: #include <queue> e3362a9488 2014-05-10 kinaba: #include <stack> e3362a9488 2014-05-10 kinaba: #include <cmath> e3362a9488 2014-05-10 kinaba: #include <cassert> e3362a9488 2014-05-10 kinaba: #include <tuple> e3362a9488 2014-05-10 kinaba: using namespace std; e3362a9488 2014-05-10 kinaba: typedef long long LL; e3362a9488 2014-05-10 kinaba: typedef complex<double> CMP; e3362a9488 2014-05-10 kinaba: e3362a9488 2014-05-10 kinaba: static const unsigned MODVAL = 1000000007; e3362a9488 2014-05-10 kinaba: struct mint e3362a9488 2014-05-10 kinaba: { e3362a9488 2014-05-10 kinaba: unsigned val; e3362a9488 2014-05-10 kinaba: mint():val(0){} e3362a9488 2014-05-10 kinaba: mint(int x):val(x%MODVAL) {} e3362a9488 2014-05-10 kinaba: mint(unsigned x):val(x%MODVAL) {} e3362a9488 2014-05-10 kinaba: mint(LL x):val(x%MODVAL) {} e3362a9488 2014-05-10 kinaba: }; e3362a9488 2014-05-10 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } e3362a9488 2014-05-10 kinaba: mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } e3362a9488 2014-05-10 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } e3362a9488 2014-05-10 kinaba: mint operator+(mint x, mint y) { return x+=y; } e3362a9488 2014-05-10 kinaba: mint operator-(mint x, mint y) { return x-=y; } e3362a9488 2014-05-10 kinaba: mint operator*(mint x, mint y) { return x*=y; } e3362a9488 2014-05-10 kinaba: e3362a9488 2014-05-10 kinaba: mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } e3362a9488 2014-05-10 kinaba: mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); } e3362a9488 2014-05-10 kinaba: mint operator/(mint x, mint y) { return x/=y; } e3362a9488 2014-05-10 kinaba: e3362a9488 2014-05-10 kinaba: vector<mint> FAC_(1,1); e3362a9488 2014-05-10 kinaba: mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*(LL)FAC_.size() ); return FAC_[n]; } e3362a9488 2014-05-10 kinaba: e3362a9488 2014-05-10 kinaba: class LongWordsDiv1 { public: e3362a9488 2014-05-10 kinaba: int count(int n) e3362a9488 2014-05-10 kinaba: { e3362a9488 2014-05-10 kinaba: vector<mint> dp(n+1); e3362a9488 2014-05-10 kinaba: dp[0] = 0; e3362a9488 2014-05-10 kinaba: dp[1] = 1; e3362a9488 2014-05-10 kinaba: for(int x=2; x<=n; ++x) e3362a9488 2014-05-10 kinaba: { e3362a9488 2014-05-10 kinaba: mint total = dp[x-1]; e3362a9488 2014-05-10 kinaba: for(int k=1; k<=x-1; ++k) e3362a9488 2014-05-10 kinaba: total += dp[k] * dp[x-1-k]; e3362a9488 2014-05-10 kinaba: dp[x] = total; e3362a9488 2014-05-10 kinaba: } e3362a9488 2014-05-10 kinaba: return (dp[n] * FAC(n)).val; e3362a9488 2014-05-10 kinaba: } e3362a9488 2014-05-10 kinaba: }; e3362a9488 2014-05-10 kinaba: e3362a9488 2014-05-10 kinaba: // BEGIN CUT HERE e3362a9488 2014-05-10 kinaba: #include <ctime> e3362a9488 2014-05-10 kinaba: double start_time; string timer() e3362a9488 2014-05-10 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } e3362a9488 2014-05-10 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) e3362a9488 2014-05-10 kinaba: { os << "{ "; e3362a9488 2014-05-10 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) e3362a9488 2014-05-10 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } e3362a9488 2014-05-10 kinaba: void verify_case(const int& Expected, const int& Received) { e3362a9488 2014-05-10 kinaba: bool ok = (Expected == Received); e3362a9488 2014-05-10 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; e3362a9488 2014-05-10 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } e3362a9488 2014-05-10 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); e3362a9488 2014-05-10 kinaba: #define END verify_case(_, LongWordsDiv1().count(n));} e3362a9488 2014-05-10 kinaba: int main(){ e3362a9488 2014-05-10 kinaba: e3362a9488 2014-05-10 kinaba: CASE(0) e3362a9488 2014-05-10 kinaba: int n = 1; e3362a9488 2014-05-10 kinaba: int _ = 1; e3362a9488 2014-05-10 kinaba: END e3362a9488 2014-05-10 kinaba: CASE(1) e3362a9488 2014-05-10 kinaba: int n = 2; e3362a9488 2014-05-10 kinaba: int _ = 2; e3362a9488 2014-05-10 kinaba: END e3362a9488 2014-05-10 kinaba: CASE(2) e3362a9488 2014-05-10 kinaba: int n = 5; e3362a9488 2014-05-10 kinaba: int _ = 1080; e3362a9488 2014-05-10 kinaba: END e3362a9488 2014-05-10 kinaba: CASE(3) e3362a9488 2014-05-10 kinaba: int n = 100; e3362a9488 2014-05-10 kinaba: int _ = 486425238; e3362a9488 2014-05-10 kinaba: END e3362a9488 2014-05-10 kinaba: /* e3362a9488 2014-05-10 kinaba: CASE(4) e3362a9488 2014-05-10 kinaba: int n = ; e3362a9488 2014-05-10 kinaba: int _ = ; e3362a9488 2014-05-10 kinaba: END e3362a9488 2014-05-10 kinaba: CASE(5) e3362a9488 2014-05-10 kinaba: int n = ; e3362a9488 2014-05-10 kinaba: int _ = ; e3362a9488 2014-05-10 kinaba: END e3362a9488 2014-05-10 kinaba: */ e3362a9488 2014-05-10 kinaba: } e3362a9488 2014-05-10 kinaba: // END CUT HERE