Combinaisons possibles dans un tableau
Ryuku
Messages postés
112
Date d'inscription
Statut
Membre
Dernière intervention
-
Ryuku Messages postés 112 Date d'inscription Statut Membre Dernière intervention -
Ryuku Messages postés 112 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je souhaite savoir comment faire pour avoir toutes les combinaisons possibles d'un tableau dynamique (Delphi) par un algorithme récursif, j'ai essayé mais en vain :
procedure Combinaison(Niveau : integer);
begin
if Niveau = -1 then
begin
AfficherVecteur;
Combinaison(0)
end
else
if Niveau = N then
begin
if Niveau - 1 < 0 then
Exit;
Permuter(Niveau, Niveau - 1);
AfficherVecteur
end
else
begin
Combinaison(Niveau + 1);
Permuter(Niveau, Niveau + 1);
Combinaison(Niveau)
end;
end;
Merci.
Je souhaite savoir comment faire pour avoir toutes les combinaisons possibles d'un tableau dynamique (Delphi) par un algorithme récursif, j'ai essayé mais en vain :
procedure Combinaison(Niveau : integer);
begin
if Niveau = -1 then
begin
AfficherVecteur;
Combinaison(0)
end
else
if Niveau = N then
begin
if Niveau - 1 < 0 then
Exit;
Permuter(Niveau, Niveau - 1);
AfficherVecteur
end
else
begin
Combinaison(Niveau + 1);
Permuter(Niveau, Niveau + 1);
Combinaison(Niveau)
end;
end;
Merci.
A voir également:
- Combinaisons possibles dans un tableau
- Tableau word - Guide
- Trier un tableau excel - Guide
- Tableau ascii - Guide
- Imprimer un tableau excel - Guide
- Tableau croisé dynamique - Guide
1 réponse
procedure Combinaison(Niveau : integer);
var I : integer;
begin
if Niveau = N + 1 then
begin
Inc(P);
Permuter(Niveau - 1, Niveau - 2);
AfficherVecteur
end
else
for I := Niveau to N do
begin
if P = 2 then
begin
P := 0;
Permuter(Niveau, I)///////////////////////////////////////
end;
Combinaison(Niveau + 1)
end;
end;
celle là marche encore mieux mais il y a un problème dans la ligne avec le commentaire
var I : integer;
begin
if Niveau = N + 1 then
begin
Inc(P);
Permuter(Niveau - 1, Niveau - 2);
AfficherVecteur
end
else
for I := Niveau to N do
begin
if P = 2 then
begin
P := 0;
Permuter(Niveau, I)///////////////////////////////////////
end;
Combinaison(Niveau + 1)
end;
end;
celle là marche encore mieux mais il y a un problème dans la ligne avec le commentaire