Artifact Content
Not logged in

Artifact 91246eeadde8d75d84e3e8116a531c3891c3a6ea


#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;

template<typename T>
struct DP4
{
	int N1, N2, N3, N4;
	vector<T> data;
	DP4(int N1, int N2, int N3, int N4, const T& t = T())
		: N1(N1), N2(N2), N3(N3), N4(N4), data(N1*N2*N3*N4, t) { assert(data.size()*sizeof(T)<(1<<26)); }
	T& operator()(int i1, int i2, int i3, int i4)
		{ return data[ (((i1*N2)+i2)*N3+i3)*N4+i4 ]; }
};

static const int MODVAL = 1000000007;

class FoxAverageSequence { public:
	int theCount(vector <int> seq) 
	{
		const int N = seq.size();

		DP4<LL> dp(N,2,41,40*N+1);
		for(int b=0; b<=40; ++b)
			if( seq[0]==-1 || seq[0]==b )
				dp(0,0,b,b) += 1;

		for(int i=1; i<N; ++i)
			for(int dn=0; dn<=1; ++dn)
			for(int  b=0;  b<=40; ++b)
			for(int  s=0;  s<=40*i; ++s)
			if( LL v = dp(i-1,dn,b,s) )
				for(int c=0; c<=min(40,s/i); ++c)
					if( seq[i]==-1 || seq[i]==c )
						if( !dn || b<=c )
							(dp(i,b>c,c,s+c) += v) %= MODVAL;

		LL ans = 0;
		for(int dn=0; dn<=1; ++dn)
		for(int  b=0;  b<=40; ++b)
		for(int  s=0;  s<=40*N; ++s)
			ans += dp(N-1,dn,b,s);
		return ans % 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(_, FoxAverageSequence().theCount(seq));}
int main(){

CASE(0)
	int seq_[] = {3, -1};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int _ = 4; 
END
CASE(1)
	int seq_[] = {5, 3, -1};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int _ = 2; 
END
CASE(2)
	int seq_[] = {-1, 0, 40};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int _ = 0; 
END
CASE(3)
	int seq_[] = {-1, 40, -1, -1, -1, 10, -1, -1, -1, 21, -1};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int _ = 579347890; 
END
CASE(4)
	int seq_[] = {-1, 12, 25, 0, 18, -1};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int _ = 58; 
END
CASE(5)
int seq_[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int _ = -1; 
END
CASE(6)
	int seq_[] = {-1};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int _ = 41; 
END
CASE(7)
	int seq_[] = {-1,-1};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int _ = (41+1)*41/2; 
END
CASE(8)
	int seq_[] = {-1,-1,0};
	  vector <int> seq(seq_, seq_+sizeof(seq_)/sizeof(*seq_)); 
	int _ = 81; 
END
}
// END CUT HERE