1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| public class algo {
public static void main(String[] args){
int resul=0;
int [] V = {1,1,1,0,2,0,1,3};
resul=RechercheExhaustive (8,V,748);
System.out.println("le resultat est" + resul );
}
static int RechercheExhaustive (int k,int V[], int s ) {
int NbrePiece;
int x;
if (s==0) { return 0; }
else { if (s<0) {return 0 ;}
else {
NbrePiece = s;
for (int i=1; i<=k; i++) {
x=RechercheExhaustive (k,V,s-V[i] ) ;
if ((x+1) < NbrePiece)
{NbrePiece=(x+1);
}
}
}
return NbrePiece;
}
}
} |
Partager