Advertisement
Guest User

Untitled

a guest
May 26th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. public class Main {
  5. public static int[] respostaCorreta;
  6. public static int nota = 1;
  7. public static int notaMaxima=1;
  8. static Map<Integer ,Integer > hm = new HashMap<Integer,Integer>();
  9. public static void main(String args[]){
  10. Scanner sc = new Scanner(System.in);
  11. int eventos = sc.nextInt();
  12. respostaCorreta = new int [eventos];
  13. sc.nextLine();
  14. for (int i=1;i<eventos+1;i++){
  15. respostaCorreta[sc.nextInt()-1]=i;
  16. }
  17. for (int i=0;i<eventos;i++) hm.put(respostaCorreta[i],i);
  18. while(sc.hasNext()){
  19. int [] vetor = new int [eventos];
  20. int [] vetorRank = new int [eventos];
  21. for (int i=1;i<eventos+1;i++) vetor[sc.nextInt()-1]=i;
  22. for (int i=0;i<eventos;i++) vetorRank[i]=hm.get(vetor[i]);
  23. for (int j=0;j<eventos;j++){
  24. backtracking(vetorRank,j,eventos);
  25. }
  26. System.out.println(notaMaxima);
  27. nota =1;
  28. notaMaxima=1;
  29. sc.nextLine();
  30. }
  31. sc.close();
  32. }
  33. public static void backtracking(int [] vetor, int posicao,int eventos){
  34. for (int i = posicao+1;i<eventos;i++){
  35. if(vetor[posicao]<vetor[i]){
  36. nota++;
  37. if (nota>notaMaxima) notaMaxima=nota;
  38. backtracking(vetor,i,eventos);
  39. nota--;
  40. }
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement