Artifact Content
Not logged in

Artifact 8e94bd05bec60fef04d5f7b139d34e04c5c932c2


#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 LadderPermutation { public:
	vector <int> createLadder(int n, int m, int k) 
	{
		try {
			vector<int> v = gen(n-k, m-1, k);
			for(int i=0; i<k; ++i)
				v.push_back(n-i);
			return v;
		} catch(...) {
			return vector<int>();
		}
	}

	vector<int> gen(int n, int m, int k) // make m blocks of length <=k
	{
		if( m==0 ) {
			if( n==0 )
				return vector<int>();
			throw "fail";
		}
		int x = min(k, n-(m-1));
		if( x <= 0 )
			throw "fail";
		vector<int> v = gen(n-x, m-1, k);
		for(int i=0; i<x; ++i)
			v.push_back(n-i);
		return v;
	}
};

// 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 vector <int>& Expected, const vector <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(_, LadderPermutation().createLadder(n, m, k));}
int main(){

CASE(0)
	int n = 4; 
	int m = 2; 
	int k = 2; 
	int __[] = {2, 1, 4, 3 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	int n = 3; 
	int m = 2; 
	int k = 2; 
	int __[] = {1, 3, 2 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(2)
	int n = 2; 
	int m = 1; 
	int k = 1; 
	vector <int> _; 
END
CASE(3)
	int n = 6; 
	int m = 3; 
	int k = 2; 
	int __[] = {2, 1, 4, 3, 6, 5 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(4)
	int n = 6; 
	int m = 2; 
	int k = 3; 
	int __[] = {3, 2, 1, 6, 5, 4 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(5)
	int n = 7; 
	int m = 4; 
	int k = 4; 
	int __[] = {1, 2, 3, 7, 6, 5, 4 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
/*
CASE(6)
	int n = ; 
	int m = ; 
	int k = ; 
	int __[] = ;
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(7)
	int n = ; 
	int m = ; 
	int k = ; 
	int __[] = ;
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
*/
}
// END CUT HERE