Cod sursa(job #254517)

Utilizator gabitzish1Gabriel Bitis gabitzish1 Data 7 februarie 2009 12:38:26
Problema Planeta Scor 0
Compilator cpp Status done
Runda Stelele Informaticii 2009, clasele 9-10, ziua 2 Marime 0.75 kb
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;
int N, K, mm;
int viz[31];

int max(int x, int y) { return x > y ? x : y; }

int main()
{
	freopen("planeta.in","r",stdin);
	freopen("planeta.out","w",stdout);

	int i, j, k, cnt, ok;
	scanf("%d %d",&N, &K);

	vector<int> v;

	
	for (i = 1; i <= N; i++) v.push_back(i);

	for (i = 1; i <= K; i++) 
	{
		next_permutation(v.begin(), v.end());
		mm = ok = 0;
		for (j = 0; j < N; j++) viz[j] = v[j];

		for (j = 1; j < N; j++)
		{
			for (k = 0; k < j; k++)
			{
				if (v[k] > v[j]) mm = max(mm, v[k]);
				if (mm > v[k]) 
				{ ok = 1; break; }
			}
			if (ok) break;
		}
		i -= ok;
	}

	for (i = 0; i < N; i++) printf("%d ",v[i]);
	return 0;
}