Artifact Content
Not logged in

Artifact 9ca9b4bf809d337c6010f7ae72bf2a6323a49d7a


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

class NumberPyramids { public:
	int count(int baseLength, int top) 
	{
		const int n = baseLength-1;
		const int s = top - (1<<n);
		if( s<0 || n>20 )
			return 0;

		vector<int> dp(s+1, 0);
		dp[0] = 1;

		for(int i=0, nCi=1; i<=n; ++i, nCi=nCi*(n-i+1)/i)
			for(int x=nCi; x<=s; ++x)
				(dp[x] += dp[x-nCi]) %= 1000000009;

		return dp[s];
	}
};

// 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(_, NumberPyramids().count(baseLength, top));}
int main(){

CASE(0)
	int baseLength = 3; 
	int top = 5; 
	int _ = 2; 
END
CASE(1)
	int baseLength = 5; 
	int top = 16; 
	int _ = 1; 
END
CASE(2)
	int baseLength = 4; 
	int top = 15; 
	int _ = 24; 
END
CASE(3)
	int baseLength = 15; 
	int top = 31556; 
	int _ = 74280915; 
END
CASE(4)
	int baseLength = 150; 
	int top = 500; 
	int _ = 0; 
END
CASE(5)
	int baseLength = 2; 
	int top = 3; 
	int _ = 2; 
END
CASE(6)
	int baseLength = 20; 
	int top = 1000000; 
	int _ = 503596690; 
END

}
// END CUT HERE