7f9fcaa19c 2013-08-02 kinaba: #include <iostream> 7f9fcaa19c 2013-08-02 kinaba: #include <sstream> 7f9fcaa19c 2013-08-02 kinaba: #include <iomanip> 7f9fcaa19c 2013-08-02 kinaba: #include <vector> 7f9fcaa19c 2013-08-02 kinaba: #include <string> 7f9fcaa19c 2013-08-02 kinaba: #include <map> 7f9fcaa19c 2013-08-02 kinaba: #include <set> 7f9fcaa19c 2013-08-02 kinaba: #include <algorithm> 7f9fcaa19c 2013-08-02 kinaba: #include <numeric> 7f9fcaa19c 2013-08-02 kinaba: #include <iterator> 7f9fcaa19c 2013-08-02 kinaba: #include <functional> 7f9fcaa19c 2013-08-02 kinaba: #include <complex> 7f9fcaa19c 2013-08-02 kinaba: #include <queue> 7f9fcaa19c 2013-08-02 kinaba: #include <stack> 7f9fcaa19c 2013-08-02 kinaba: #include <cmath> 7f9fcaa19c 2013-08-02 kinaba: #include <cassert> 7f9fcaa19c 2013-08-02 kinaba: #include <tuple> 7f9fcaa19c 2013-08-02 kinaba: using namespace std; 7f9fcaa19c 2013-08-02 kinaba: typedef long long LL; 7f9fcaa19c 2013-08-02 kinaba: typedef complex<double> CMP; 7f9fcaa19c 2013-08-02 kinaba: 7f9fcaa19c 2013-08-02 kinaba: static const unsigned MODVAL = 1000000007; 7f9fcaa19c 2013-08-02 kinaba: struct mint 7f9fcaa19c 2013-08-02 kinaba: { 7f9fcaa19c 2013-08-02 kinaba: unsigned val; 7f9fcaa19c 2013-08-02 kinaba: mint():val(0){} 7f9fcaa19c 2013-08-02 kinaba: mint(int x):val(x%MODVAL) {} 7f9fcaa19c 2013-08-02 kinaba: mint(unsigned x):val(x%MODVAL) {} 7f9fcaa19c 2013-08-02 kinaba: mint(LL x):val(x%MODVAL) {} 7f9fcaa19c 2013-08-02 kinaba: }; 7f9fcaa19c 2013-08-02 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } 7f9fcaa19c 2013-08-02 kinaba: mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } 7f9fcaa19c 2013-08-02 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } 7f9fcaa19c 2013-08-02 kinaba: mint operator+(mint x, mint y) { return x+=y; } 7f9fcaa19c 2013-08-02 kinaba: mint operator-(mint x, mint y) { return x-=y; } 7f9fcaa19c 2013-08-02 kinaba: mint operator*(mint x, mint y) { return x*=y; } 7f9fcaa19c 2013-08-02 kinaba: 7f9fcaa19c 2013-08-02 kinaba: vector< vector<mint> > CP_; 7f9fcaa19c 2013-08-02 kinaba: mint C(int n, int k) { 7f9fcaa19c 2013-08-02 kinaba: while( CP_.size() <= n ) { 7f9fcaa19c 2013-08-02 kinaba: int nn = CP_.size(); 7f9fcaa19c 2013-08-02 kinaba: CP_.push_back(vector<mint>(nn+1,1)); 7f9fcaa19c 2013-08-02 kinaba: for(int kk=1; kk<nn; ++kk) 7f9fcaa19c 2013-08-02 kinaba: CP_[nn][kk] = CP_[nn-1][kk-1] + CP_[nn-1][kk]; 7f9fcaa19c 2013-08-02 kinaba: } 7f9fcaa19c 2013-08-02 kinaba: return k<0 || n<k ? 0 : CP_[n][k]; 7f9fcaa19c 2013-08-02 kinaba: } 7f9fcaa19c 2013-08-02 kinaba: 7f9fcaa19c 2013-08-02 kinaba: class LISNumber { public: 7f9fcaa19c 2013-08-02 kinaba: int count(vector <int> cardsnum, int K) 7f9fcaa19c 2013-08-02 kinaba: { 7f9fcaa19c 2013-08-02 kinaba: memo.assign(accumulate(cardsnum.begin(), cardsnum.end(), 1)*cardsnum.size(), -1); 7f9fcaa19c 2013-08-02 kinaba: return rec(1, 0, cardsnum, 0, K); 7f9fcaa19c 2013-08-02 kinaba: } 7f9fcaa19c 2013-08-02 kinaba: 7f9fcaa19c 2013-08-02 kinaba: vector<int> memo; 7f9fcaa19c 2013-08-02 kinaba: int rec(int blks, int may, const vector<int>& cards, int i, int K) 7f9fcaa19c 2013-08-02 kinaba: { 7f9fcaa19c 2013-08-02 kinaba: if(i == cards.size()) 7f9fcaa19c 2013-08-02 kinaba: return (K == may); 7f9fcaa19c 2013-08-02 kinaba: if(K<may) 7f9fcaa19c 2013-08-02 kinaba: return 0; 7f9fcaa19c 2013-08-02 kinaba: 7f9fcaa19c 2013-08-02 kinaba: int key = may*cards.size() + i; 7f9fcaa19c 2013-08-02 kinaba: if(memo[key] != -1) 7f9fcaa19c 2013-08-02 kinaba: return memo[key]; 7f9fcaa19c 2013-08-02 kinaba: 7f9fcaa19c 2013-08-02 kinaba: int c = cards[i]; 7f9fcaa19c 2013-08-02 kinaba: 7f9fcaa19c 2013-08-02 kinaba: mint total = 0; 7f9fcaa19c 2013-08-02 kinaba: for(int use=1; use<=blks && use<=c; ++use) 7f9fcaa19c 2013-08-02 kinaba: { 7f9fcaa19c 2013-08-02 kinaba: for(int use_may=0; use_may<=use; ++use_may) 7f9fcaa19c 2013-08-02 kinaba: if(use-use_may<=blks-may && use_may<=may) 7f9fcaa19c 2013-08-02 kinaba: total += C(blks-may, use-use_may) * C(may, use_may) * C(c-1, use-1) * rec(blks+c,may-use_may+c,cards,i+1,K); 7f9fcaa19c 2013-08-02 kinaba: } 7f9fcaa19c 2013-08-02 kinaba: return memo[key] = total.val; 7f9fcaa19c 2013-08-02 kinaba: } 7f9fcaa19c 2013-08-02 kinaba: }; 7f9fcaa19c 2013-08-02 kinaba: 7f9fcaa19c 2013-08-02 kinaba: // BEGIN CUT HERE 7f9fcaa19c 2013-08-02 kinaba: #include <ctime> 7f9fcaa19c 2013-08-02 kinaba: double start_time; string timer() 7f9fcaa19c 2013-08-02 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 7f9fcaa19c 2013-08-02 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 7f9fcaa19c 2013-08-02 kinaba: { os << "{ "; 7f9fcaa19c 2013-08-02 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 7f9fcaa19c 2013-08-02 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 7f9fcaa19c 2013-08-02 kinaba: void verify_case(const int& Expected, const int& Received) { 7f9fcaa19c 2013-08-02 kinaba: bool ok = (Expected == Received); 7f9fcaa19c 2013-08-02 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 7f9fcaa19c 2013-08-02 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 7f9fcaa19c 2013-08-02 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 7f9fcaa19c 2013-08-02 kinaba: #define END verify_case(_, LISNumber().count(cardsnum, K));} 7f9fcaa19c 2013-08-02 kinaba: int main(){ 7f9fcaa19c 2013-08-02 kinaba: /* 7f9fcaa19c 2013-08-02 kinaba: CASE(0) 7f9fcaa19c 2013-08-02 kinaba: int cardsnum_[] = {1, 1, 1}; 7f9fcaa19c 2013-08-02 kinaba: vector <int> cardsnum(cardsnum_, cardsnum_+sizeof(cardsnum_)/sizeof(*cardsnum_)); 7f9fcaa19c 2013-08-02 kinaba: int K = 2; 7f9fcaa19c 2013-08-02 kinaba: int _ = 4; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: */ 7f9fcaa19c 2013-08-02 kinaba: CASE(1) 7f9fcaa19c 2013-08-02 kinaba: int cardsnum_[] = {2}; 7f9fcaa19c 2013-08-02 kinaba: vector <int> cardsnum(cardsnum_, cardsnum_+sizeof(cardsnum_)/sizeof(*cardsnum_)); 7f9fcaa19c 2013-08-02 kinaba: int K = 1; 7f9fcaa19c 2013-08-02 kinaba: int _ = 0; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: CASE(2) 7f9fcaa19c 2013-08-02 kinaba: int cardsnum_[] = {36, 36, 36, 36, 36}; 7f9fcaa19c 2013-08-02 kinaba: vector <int> cardsnum(cardsnum_, cardsnum_+sizeof(cardsnum_)/sizeof(*cardsnum_)); 7f9fcaa19c 2013-08-02 kinaba: int K = 36; 7f9fcaa19c 2013-08-02 kinaba: int _ = 1; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: CASE(3) 7f9fcaa19c 2013-08-02 kinaba: int cardsnum_[] = {3, 2, 11, 5, 7}; 7f9fcaa19c 2013-08-02 kinaba: vector <int> cardsnum(cardsnum_, cardsnum_+sizeof(cardsnum_)/sizeof(*cardsnum_)); 7f9fcaa19c 2013-08-02 kinaba: int K = 20; 7f9fcaa19c 2013-08-02 kinaba: int _ = 474640725; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: CASE(4) 7f9fcaa19c 2013-08-02 kinaba: int cardsnum_[] = {31, 4, 15, 9, 26, 5, 35, 8, 9, 7, 9, 32, 3, 8, 4, 6, 26}; 7f9fcaa19c 2013-08-02 kinaba: vector <int> cardsnum(cardsnum_, cardsnum_+sizeof(cardsnum_)/sizeof(*cardsnum_)); 7f9fcaa19c 2013-08-02 kinaba: int K = 58; 7f9fcaa19c 2013-08-02 kinaba: int _ = 12133719; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: CASE(5) 7f9fcaa19c 2013-08-02 kinaba: int cardsnum_[] = {27, 18, 28, 18, 28, 4, 5, 9, 4, 5, 23, 5, 7f9fcaa19c 2013-08-02 kinaba: 36, 28, 7, 4, 7, 13, 5, 26, 6, 24, 9, 7, 7f9fcaa19c 2013-08-02 kinaba: 7, 5, 7, 24, 7, 9, 36, 9, 9, 9, 5, 9}; 7f9fcaa19c 2013-08-02 kinaba: vector <int> cardsnum(cardsnum_, cardsnum_+sizeof(cardsnum_)/sizeof(*cardsnum_)); 7f9fcaa19c 2013-08-02 kinaba: int K = 116; 7f9fcaa19c 2013-08-02 kinaba: int _ = 516440918; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: CASE(6) 7f9fcaa19c 2013-08-02 kinaba: int cardsnum_[] = { 7f9fcaa19c 2013-08-02 kinaba: 36,36,36,36,36,36, 7f9fcaa19c 2013-08-02 kinaba: 36,36,36,36,36,36, 7f9fcaa19c 2013-08-02 kinaba: 36,36,36,36,36,36, 7f9fcaa19c 2013-08-02 kinaba: 36,36,36,36,36,36, 7f9fcaa19c 2013-08-02 kinaba: 36,36,36,36,36,36, 7f9fcaa19c 2013-08-02 kinaba: 36,36,36,36,36,36}; 7f9fcaa19c 2013-08-02 kinaba: vector <int> cardsnum(cardsnum_, cardsnum_+sizeof(cardsnum_)/sizeof(*cardsnum_)); 7f9fcaa19c 2013-08-02 kinaba: int K = 36*36; 7f9fcaa19c 2013-08-02 kinaba: int _ = -1; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: /* 7f9fcaa19c 2013-08-02 kinaba: CASE(7) 7f9fcaa19c 2013-08-02 kinaba: int cardsnum_[] = ; 7f9fcaa19c 2013-08-02 kinaba: vector <int> cardsnum(cardsnum_, cardsnum_+sizeof(cardsnum_)/sizeof(*cardsnum_)); 7f9fcaa19c 2013-08-02 kinaba: int K = ; 7f9fcaa19c 2013-08-02 kinaba: int _ = ; 7f9fcaa19c 2013-08-02 kinaba: END 7f9fcaa19c 2013-08-02 kinaba: */ 7f9fcaa19c 2013-08-02 kinaba: } 7f9fcaa19c 2013-08-02 kinaba: // END CUT HERE