892b20bec8 2015-04-28 kinaba: #include <iostream> 892b20bec8 2015-04-28 kinaba: #include <sstream> 892b20bec8 2015-04-28 kinaba: #include <iomanip> 892b20bec8 2015-04-28 kinaba: #include <vector> 892b20bec8 2015-04-28 kinaba: #include <string> 892b20bec8 2015-04-28 kinaba: #include <map> 892b20bec8 2015-04-28 kinaba: #include <set> 892b20bec8 2015-04-28 kinaba: #include <algorithm> 892b20bec8 2015-04-28 kinaba: #include <numeric> 892b20bec8 2015-04-28 kinaba: #include <iterator> 892b20bec8 2015-04-28 kinaba: #include <functional> 892b20bec8 2015-04-28 kinaba: #include <complex> 892b20bec8 2015-04-28 kinaba: #include <queue> 892b20bec8 2015-04-28 kinaba: #include <stack> 892b20bec8 2015-04-28 kinaba: #include <cmath> 892b20bec8 2015-04-28 kinaba: #include <cassert> 892b20bec8 2015-04-28 kinaba: #include <tuple> 892b20bec8 2015-04-28 kinaba: using namespace std; 892b20bec8 2015-04-28 kinaba: typedef long long LL; 892b20bec8 2015-04-28 kinaba: typedef complex<double> CMP; 892b20bec8 2015-04-28 kinaba: 892b20bec8 2015-04-28 kinaba: static const unsigned MODVAL = 1000000007; 892b20bec8 2015-04-28 kinaba: struct mint 892b20bec8 2015-04-28 kinaba: { 892b20bec8 2015-04-28 kinaba: unsigned val; 892b20bec8 2015-04-28 kinaba: mint():val(0){} 892b20bec8 2015-04-28 kinaba: mint(int x):val(x%MODVAL) {} 892b20bec8 2015-04-28 kinaba: mint(unsigned x):val(x%MODVAL) {} 892b20bec8 2015-04-28 kinaba: mint(LL x):val(x%MODVAL) {} 892b20bec8 2015-04-28 kinaba: }; 892b20bec8 2015-04-28 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } 892b20bec8 2015-04-28 kinaba: mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } 892b20bec8 2015-04-28 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } 892b20bec8 2015-04-28 kinaba: mint operator+(mint x, mint y) { return x+=y; } 892b20bec8 2015-04-28 kinaba: mint operator-(mint x, mint y) { return x-=y; } 892b20bec8 2015-04-28 kinaba: mint operator*(mint x, mint y) { return x*=y; } 892b20bec8 2015-04-28 kinaba: 892b20bec8 2015-04-28 kinaba: mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } 892b20bec8 2015-04-28 kinaba: 892b20bec8 2015-04-28 kinaba: class Nine { public: 892b20bec8 2015-04-28 kinaba: int count(int N, vector <int> d) 892b20bec8 2015-04-28 kinaba: { 892b20bec8 2015-04-28 kinaba: const int M = d.size(); 892b20bec8 2015-04-28 kinaba: 892b20bec8 2015-04-28 kinaba: vector<int> cnt(1<<N); 892b20bec8 2015-04-28 kinaba: for(int di: d) 892b20bec8 2015-04-28 kinaba: cnt[di]++; 892b20bec8 2015-04-28 kinaba: 892b20bec8 2015-04-28 kinaba: vector<vector<mint>> pat(M+1, vector<mint>(9)); 892b20bec8 2015-04-28 kinaba: pat[0][0] = 1; 892b20bec8 2015-04-28 kinaba: for(int cnt=1; cnt<=M; ++cnt) { 892b20bec8 2015-04-28 kinaba: for(int pre=0; pre<9; ++pre) 892b20bec8 2015-04-28 kinaba: for(int incr=0; incr<=9; ++incr) 892b20bec8 2015-04-28 kinaba: pat[cnt][(pre+incr)%9] += pat[cnt-1][pre]; 892b20bec8 2015-04-28 kinaba: } 892b20bec8 2015-04-28 kinaba: 892b20bec8 2015-04-28 kinaba: int TBLMAX = 1; for(int i=0; i<N; ++i) TBLMAX*=9; 892b20bec8 2015-04-28 kinaba: vector<mint> dp(TBLMAX); 892b20bec8 2015-04-28 kinaba: dp[0] = 1; 892b20bec8 2015-04-28 kinaba: 892b20bec8 2015-04-28 kinaba: for(int mask=0; mask<(1<<N); ++mask) 892b20bec8 2015-04-28 kinaba: { 892b20bec8 2015-04-28 kinaba: int c = cnt[mask]; // #{i | d[i] = mask} 892b20bec8 2015-04-28 kinaba: vector<mint> dp2(TBLMAX); 892b20bec8 2015-04-28 kinaba: 892b20bec8 2015-04-28 kinaba: for(int rem_state=0; rem_state<TBLMAX; ++rem_state) 892b20bec8 2015-04-28 kinaba: { 892b20bec8 2015-04-28 kinaba: for(int tgt=0; tgt<9; ++tgt) 892b20bec8 2015-04-28 kinaba: { 892b20bec8 2015-04-28 kinaba: int r2 = 0; 892b20bec8 2015-04-28 kinaba: for(int f=1,i=0; i<N; f*=9,++i) 892b20bec8 2015-04-28 kinaba: { 892b20bec8 2015-04-28 kinaba: if(mask&(1<<i)) { 892b20bec8 2015-04-28 kinaba: r2 += ((rem_state/f + tgt*c)%9)*f; 892b20bec8 2015-04-28 kinaba: } else { 892b20bec8 2015-04-28 kinaba: r2 += (rem_state/f%9)*f; 892b20bec8 2015-04-28 kinaba: } 892b20bec8 2015-04-28 kinaba: } 892b20bec8 2015-04-28 kinaba: dp2[r2] += dp[rem_state] * pat[c][tgt]; 892b20bec8 2015-04-28 kinaba: } 892b20bec8 2015-04-28 kinaba: } 892b20bec8 2015-04-28 kinaba: 892b20bec8 2015-04-28 kinaba: dp = std::move(dp2); 892b20bec8 2015-04-28 kinaba: } 892b20bec8 2015-04-28 kinaba: return dp[0].val; 892b20bec8 2015-04-28 kinaba: } 892b20bec8 2015-04-28 kinaba: 892b20bec8 2015-04-28 kinaba: }; 892b20bec8 2015-04-28 kinaba: 892b20bec8 2015-04-28 kinaba: // BEGIN CUT HERE 892b20bec8 2015-04-28 kinaba: #include <ctime> 892b20bec8 2015-04-28 kinaba: double start_time; string timer() 892b20bec8 2015-04-28 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 892b20bec8 2015-04-28 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 892b20bec8 2015-04-28 kinaba: { os << "{ "; 892b20bec8 2015-04-28 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 892b20bec8 2015-04-28 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 892b20bec8 2015-04-28 kinaba: void verify_case(const int& Expected, const int& Received) { 892b20bec8 2015-04-28 kinaba: bool ok = (Expected == Received); 892b20bec8 2015-04-28 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 892b20bec8 2015-04-28 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 892b20bec8 2015-04-28 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 892b20bec8 2015-04-28 kinaba: #define END verify_case(_, Nine().count(N, d));} 892b20bec8 2015-04-28 kinaba: int main(){ 892b20bec8 2015-04-28 kinaba: 892b20bec8 2015-04-28 kinaba: CASE(0) 892b20bec8 2015-04-28 kinaba: int N = 2; 892b20bec8 2015-04-28 kinaba: int d_[] = {1,2}; 892b20bec8 2015-04-28 kinaba: vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 892b20bec8 2015-04-28 kinaba: int _ = 4; 892b20bec8 2015-04-28 kinaba: END 892b20bec8 2015-04-28 kinaba: CASE(1) 892b20bec8 2015-04-28 kinaba: int N = 2; 892b20bec8 2015-04-28 kinaba: int d_[] = {1,2,3}; 892b20bec8 2015-04-28 kinaba: vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 892b20bec8 2015-04-28 kinaba: int _ = 16; 892b20bec8 2015-04-28 kinaba: END 892b20bec8 2015-04-28 kinaba: CASE(2) 892b20bec8 2015-04-28 kinaba: int N = 1; 892b20bec8 2015-04-28 kinaba: int d_[] = {0,0,1}; 892b20bec8 2015-04-28 kinaba: vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 892b20bec8 2015-04-28 kinaba: int _ = 200; 892b20bec8 2015-04-28 kinaba: END 892b20bec8 2015-04-28 kinaba: CASE(3) 892b20bec8 2015-04-28 kinaba: int N = 5; 892b20bec8 2015-04-28 kinaba: int d_[] = {1,3,5,8,24,22,25,21,30,2,4,0,6,7,9,11,14,13,12,15,18,17,16,19,26,29,31,28,27,10,20,23}; 892b20bec8 2015-04-28 kinaba: vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 892b20bec8 2015-04-28 kinaba: int _ = 450877328; 892b20bec8 2015-04-28 kinaba: END 892b20bec8 2015-04-28 kinaba: CASE(4) 892b20bec8 2015-04-28 kinaba: int N = 5; 892b20bec8 2015-04-28 kinaba: int d_[] = {31,31,31,31,31}; 892b20bec8 2015-04-28 kinaba: vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 892b20bec8 2015-04-28 kinaba: int _ = 11112; 892b20bec8 2015-04-28 kinaba: END 892b20bec8 2015-04-28 kinaba: /* 892b20bec8 2015-04-28 kinaba: CASE(5) 892b20bec8 2015-04-28 kinaba: int N = ; 892b20bec8 2015-04-28 kinaba: int d_[] = ; 892b20bec8 2015-04-28 kinaba: vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 892b20bec8 2015-04-28 kinaba: int _ = ; 892b20bec8 2015-04-28 kinaba: END 892b20bec8 2015-04-28 kinaba: CASE(6) 892b20bec8 2015-04-28 kinaba: int N = ; 892b20bec8 2015-04-28 kinaba: int d_[] = ; 892b20bec8 2015-04-28 kinaba: vector <int> d(d_, d_+sizeof(d_)/sizeof(*d_)); 892b20bec8 2015-04-28 kinaba: int _ = ; 892b20bec8 2015-04-28 kinaba: END 892b20bec8 2015-04-28 kinaba: */ 892b20bec8 2015-04-28 kinaba: } 892b20bec8 2015-04-28 kinaba: // END CUT HERE