Artifact 2ad7ecc836973d8a5085143426025b9f6524f95a
#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;
struct mint
{
int val;
mint():val(0){}
mint(int x):val(x%MODVAL) {} // x>=0
mint(size_t x):val(x%MODVAL) {} // x>=0
mint(LL x):val(x%MODVAL) {} // x>=0
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint operator+(mint x, mint y) { return x+=y; }
mint operator*(mint x, mint y) { return x*=y; }
class BricksN { public:
int countStructures(int w, int h, int k)
{
memo1.clear();
memo2.clear();
return rec(w, h, k).val;
}
map<int,mint> memo1;
mint rec(int w, int h, int k)
{
if( h == 0 ) return 1;
if( w <= 0 ) return 1;
const int key = w*51+h;
if( memo1.count(key) )
return memo1[key];
mint sum = 1;
for(int s=0; s<w; ++s)
for(int ww=1; s+ww<=w; ++ww)
sum += full(ww, k) * rec(ww, h-1, k) * rec(w-(s+ww+1), h, k);
return memo1[key] = sum;
}
map<int,mint> memo2;
mint full(int w, int k)
{
if( w <= 0 ) return 1;
const int key = w;
if( memo2.count(key) )
return memo2[key];
mint sum = 0;
for(int ww=1; ww<=min(w,k); ++ww)
sum += full(w-ww, k);
return memo2[key] = sum;
}
};
// 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(_, BricksN().countStructures(w, h, k));}
int main(){
CASE(0)
int w = 3;
int h = 1;
int k = 3;
int _ = 13;
END
CASE(1)
int w = 3;
int h = 2;
int k = 3;
int _ = 83;
END
CASE(2)
int w = 1;
int h = 5;
int k = 1;
int _ = 6;
END
CASE(3)
int w = 10;
int h = 10;
int k = 3;
int _ = 288535435;
END
CASE(4)
int w = 50;
int h = 50;
int k = 50;
int _ = -1;
END
CASE(5)
int w = 1;
int h = 1;
int k = 1;
int _ = 1;
END
}
// END CUT HERE