Artifact 4a5bd572b13e0e84499d77d41bfbaa50a2f11fc5
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
static const int MODVAL = 1000000007;
LL C[201][201];
class PickAndDelete { public:
int count(vector <string> S_)
{
init_C();
vector<int> 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<int>& S)
{
map<multiset<int>, LL> dp;
dp[multiset<int>()] = 1;
for(int i=0; i<S.size(); ++i)
{
int next = S[i];
map<multiset<int>, LL> dp2;
for(map<multiset<int>,LL>::iterator it=dp.begin(); it!=dp.end(); ++it)
{
const multiset<int>& sig = it->first;
if( sig.size() < next ) {
multiset<int> new_sig = sig;
new_sig.insert(1);
(dp2[new_sig] += it->second*(next-sig.size())) %= MODVAL;
}
for(multiset<int>::const_iterator jt=sig.begin(); jt!=sig.end(); ++jt)
{
multiset<int> 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<multiset<int>,LL>::iterator it=dp.begin(); it!=dp.end(); ++it)
{
LL n = it->second;
int tt = S.size();
for(multiset<int>::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 <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::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 <string> S(S_, S_+sizeof(S_)/sizeof(*S_));
int _ = 3;
END
CASE(1)
string S_[] = {"2 2 2 2 2 2 2 2 2"};
vector <string> S(S_, S_+sizeof(S_)/sizeof(*S_));
int _ = 512;
END
CASE(2)
string S_[] = {"5", " 1 ", "2"};
vector <string> S(S_, S_+sizeof(S_)/sizeof(*S_));
int _ = 34;
END
CASE(3)
string S_[] = {"3 ", "14159 265", "3589 7", " 932"};
vector <string> S(S_, S_+sizeof(S_)/sizeof(*S_));
int _ = 353127147;
END
/*
CASE(4)
string S_[] = ;
vector <string> S(S_, S_+sizeof(S_)/sizeof(*S_));
int _ = ;
END
CASE(5)
string S_[] = ;
vector <string> S(S_, S_+sizeof(S_)/sizeof(*S_));
int _ = ;
END
*/
}
// END CUT HERE