Artifact Content
Not logged in

Artifact b8edf4ca77074ee34518ae8bd3ceead6167d0f9c


#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 PalindromfulString { public:
	long long count(int N, int M, int K) 
	{
		vector<int> tmp;
		return rec(N, M, K, tmp, 0);
	}

	static LL rec(int N, int M, int K, vector<int>& cur, int usedMax)
	{
		if( cur.size() == N )
		{
			int pc=0;
			for(int s=0; s+M<=N; ++s)
				if( isPalin(cur, s, s+M) )
					pc++;
			return (pc>=K ? P(26, usedMax) : 0);
		}
		else
		{
			LL sum = 0;
			for(int k=1; k<=usedMax+1; ++k)
			{
				cur.push_back(k);
				sum += rec(N, M, K, cur, max(usedMax,k));
				cur.pop_back();
			}
			return sum;
		}
	}

	static bool isPalin(const vector<int>& v, int s, int e)
	{
		for( ; s<=--e; ++s)
			if( v[s] != v[e] )
				return false;
		return true;
	}

	static LL P(int v, int n)
	{
		LL x = 1;
		for(int i=0; i<n; ++i)
			x *= v-i;
		return x;
	}
};

// 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 long long& Expected, const long long& 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(_, PalindromfulString().count(N, M, K));}
int main(){

CASE(0)
	int N = 2; 
	int M = 2; 
	int K = 1; 
	long long _ = 26LL; 
END
CASE(1)
	int N = 2; 
	int M = 2; 
	int K = 0; 
	long long _ = 676LL; 
END
CASE(2)
	int N = 3; 
	int M = 2; 
	int K = 1; 
	long long _ = 1326LL; 
END
CASE(3)
	int N = 4; 
	int M = 4; 
	int K = 1; 
	long long _ = 676LL; 
END
CASE(4)
	int N = 7; 
	int M = 3; 
	int K = 3; 
	long long _ = 4310176LL; 
END
CASE(5)
	int N = 11; 
	int M = 2; 
	int K = 0; 
	long long _ = -1LL; 
END
CASE(6)
	int N = 11; 
	int M = 5; 
	int K = 0; 
	long long _ = -1LL; 
END

}
// END CUT HERE