Artifact Content
Not logged in

Artifact b836622385c9a1655c3af192c25965e1d1768f31


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
typedef long long LL;

class PolygonDecomposition
{
public:
	int howMany(int n, int k) 
	{
		if( n-2 < k )
			return -1;

		LL dp[101][101] = {};
		dp[2][0] = 1;
		for(int N=3; N<=n; ++N)
			dp[N][1] = 1;

		for(int N=4; N<=n; ++N)
		for(int K=2; K<=k; ++K)
		{
			LL sum = 0;
			for(LL v=3; v<=N-1; ++v) // use 1--v and don't use 1--3, ..., 1--(v-1)
				for(int x=1; x<=K-1; ++x) // left: x pieces, right: K-x pieces
					sum += (dp[v-1][x-1]+dp[v-1][x]) * dp[N-v+2][K-x] % 1000000000;

			// don't use 1--*; if use 2--N, we'll have dp[N-1][K-1] cuts
			//                 otherwise, will have dp[N-1][K] because 2--1--N
			//                            can be regarded as a single edge
			sum += dp[N-1][K-1] + dp[N-1][K];
			dp[N][K] = sum % 1000000000;
		}
		return (int) dp[n][k];
	}


// BEGIN CUT HERE
	public:
	void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); }
	private:
	template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
	void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
	void test_case_0() { int Arg0 = 4; int Arg1 = 2; int Arg2 = 2; verify_case(0, Arg2, howMany(Arg0, Arg1)); }
	void test_case_1() { int Arg0 = 100; int Arg1 = 1; int Arg2 = 1; verify_case(1, Arg2, howMany(Arg0, Arg1)); }
	void test_case_2() { int Arg0 = 6; int Arg1 = 4; int Arg2 = 14; verify_case(2, Arg2, howMany(Arg0, Arg1)); }
	void test_case_3() { int Arg0 = 31; int Arg1 = 20; int Arg2 = 956146480; verify_case(3, Arg2, howMany(Arg0, Arg1)); }
	void test_case_4() { int Arg0 = 3; int Arg1 = 4; int Arg2 = -1; verify_case(4, Arg2, howMany(Arg0, Arg1)); }

// END CUT HERE
};
// BEGIN CUT HERE 
int main() { PolygonDecomposition().run_test(-1); }
// END CUT HERE