Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.inf4705_tp2.poly;
- import java.util.ArrayList;
- public class Dynamic {
- public static void DynamicAlgo(ArrayList<Bloc> blocs, int nbOfBlocs)
- {
- int[] H = new int[nbOfBlocs];
- int[] nbBlocsUsed = new int [nbOfBlocs];
- for(int i = 0; i < nbOfBlocs; i++)
- {
- H[i] = blocs.get(i).GetHauteurBloc();
- nbBlocsUsed[i] = 1;
- }
- for(int i = 1; i < nbOfBlocs; i++)
- {
- for(int j = 0; j < i; j++)
- {
- if( blocs.get(i).GetLargeurBloc() < blocs.get(j).GetLargeurBloc() &&
- blocs.get(i).GetProfondeurBloc() < blocs.get(j).GetProfondeurBloc() &&
- H[i] < H[j] + blocs.get(i).GetHauteurBloc())
- {
- H[i] = H[j] + blocs.get(i).GetHauteurBloc();
- nbBlocsUsed[i]++;
- }
- }
- }
- int maxHeight = -1;
- int maxBlocsUsed = 0;
- for(int i = 0; i < nbOfBlocs; i++)
- {
- if(H[i] > maxHeight)
- {
- maxHeight = H[i];
- maxBlocsUsed = nbBlocsUsed[i];
- }
- }
- System.out.println(maxHeight);
- System.out.println(maxBlocsUsed);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement