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 36 37 38 39 40
| import java.util.ArrayList;
public class algo {
public static void main(String[] args){
int resul=0;
//int [] V = {1,1,1,0,2,0,1,3};
ArrayList<Integer> test = new ArrayList<Integer>();
test.add(1);
test.add(2);
resul=RechercheExhaustive (2,test,5);
System.out.println("le resultat est" + resul );
}
static int RechercheExhaustive (int k,ArrayList<Integer> 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.get(i) ) ;
if ((x+1) < NbrePiece)
{NbrePiece=(x+1);
}
}
}
return NbrePiece;
}
}
} |
Partager