Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. package com.inf4705_tp2.poly;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. public class Dynamic {
  6. public static void DynamicAlgo(ArrayList<Bloc> blocs, int nbOfBlocs)
  7. {
  8. int[] H = new int[nbOfBlocs];
  9. int[] nbBlocsUsed = new int [nbOfBlocs];
  10. for(int i = 0; i < nbOfBlocs; i++)
  11. {
  12. H[i] = blocs.get(i).GetHauteurBloc();
  13. nbBlocsUsed[i] = 1;
  14. }
  15.  
  16. for(int i = 1; i < nbOfBlocs; i++)
  17. {
  18. for(int j = 0; j < i; j++)
  19. {
  20. if( blocs.get(i).GetLargeurBloc() < blocs.get(j).GetLargeurBloc() &&
  21. blocs.get(i).GetProfondeurBloc() < blocs.get(j).GetProfondeurBloc() &&
  22. H[i] < H[j] + blocs.get(i).GetHauteurBloc())
  23. {
  24. H[i] = H[j] + blocs.get(i).GetHauteurBloc();
  25. nbBlocsUsed[i]++;
  26. }
  27. }
  28. }
  29.  
  30. int maxHeight = -1;
  31. int maxBlocsUsed = 0;
  32. for(int i = 0; i < nbOfBlocs; i++)
  33. {
  34. if(H[i] > maxHeight)
  35. {
  36. maxHeight = H[i];
  37. maxBlocsUsed = nbBlocsUsed[i];
  38. }
  39. }
  40. System.out.println(maxHeight);
  41. System.out.println(maxBlocsUsed);
  42.  
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement