Voltar

Análise Combinatória - Matemática

0 Curtidas
#include "algorithms.h"
#include 
#include 
#include 
#include 
#include 
#include 


char *alg_mark;
int *alg_lista;

//r most be less or equal than n, index=0
void perm(int* vector, int n, int r, int index, void (*func) (int*,int)) {
    if (r==0) {
        func(alg_lista,index);
        return;
    }
    for (int i=0; in)) return;
    alg_mark = new char[n];
    alg_lista = new int[r];
    memset(alg_mark,0,n);
    perm(vector,n,r,0,func);
    delete [] alg_mark;
    delete [] alg_lista;
}


using namespace std;

char entrada[20];

int main()
{
    int tam = 0;
    int caseN = 1;
    while ((cin >> entrada) && (tam = strlen(entrada)))
    {
        sort(entrada, entrada + tam);
        cout << "Case " << caseN++ << "\n";
        do
        {
            cout << entrada << "\n";
        } while(next_permutation(entrada, entrada + tam));
        cout << endl;
    }
}

/**
 * Receives a vector of n integers and does all possible combinations
 * of r elements. Once a new combination if found, it calls the received
 * function func with the computed vector and its respective size (r)
 */
void combinations(int* vector, int n, int r, void (*func) (int*,int)) {
    if ((r<0) || (r>n)) return;
    alg_lista = new int[r];
    comb(vector,n,r,0,func);
    delete [] alg_lista;
}

Problemas relacionados
  Nome Comentário
Ainda não há nenhum problema relacionado a esse conteúdo

Comentários


Postagens neste fórum só são permitidas para membros com conta ativa. Por favor, efetue login or cadastro para postar.