Cod sursa(job #154285)

Utilizator alecmanAchim Ioan Alexandru alecman Data 11 martie 2008 07:59:33
Problema Combinari Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.17 kb
#include<stdio.h>

#define INPUT "combinari.in"
#define OUTPUT "combinari.out"

FILE *fin=fopen(INPUT, "r"),*fout=fopen(OUTPUT, "w");

int st[20], k, n, valMax;

void readValues();

inline void init();

inline int succesor();

inline int valid();

int solutie();

void printSolution();

int main(){
  int as, ev, l;
  readValues();
  k = 1;
  init();
  while(k)
  {
    l = 1;
    do
    {
      as = succesor();
      if( as ) ev = valid();
      if(( as && ev) || !as ) l=0;
    } while (l);
    if( as )
    {
      if( solutie() )
      {
        printSolution();
      }
      else
      {
	++k;
	init();
      }
    }
    else
      --k;
  }
  fclose(fin);
  fclose(fout);
  return 0;
}

void readValues()
{
  fscanf(fin, "%d %d", &n, &valMax);
}

inline void init()
{
  st[k]=st[k-1];
}

inline int succesor()
{
  if(st[k] < n)
  {
    ++st[k];
    return 1;
  }
  return 0;
}

inline int valid()
{
  return 1;
}

int solutie()
{
  if(k == valMax)
    return 1;
  return 0;
}

void printSolution()
{
  for(int i = 1; i <= valMax; ++i)
  {
    fprintf(fout, "%d ", st[i]);
  }
  fprintf(fout, "\n");
}