Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.HashMap;
- import java.util.Map;
- public class Main {
- public static int[] respostaCorreta;
- public static int nota = 1;
- public static int notaMaxima=1;
- static Map<Integer ,Integer > hm = new HashMap<Integer,Integer>();
- public static void main(String args[]){
- Scanner sc = new Scanner(System.in);
- int eventos = sc.nextInt();
- respostaCorreta = new int [eventos];
- sc.nextLine();
- for (int i=1;i<eventos+1;i++){
- respostaCorreta[sc.nextInt()-1]=i;
- }
- for (int i=0;i<eventos;i++) hm.put(respostaCorreta[i],i);
- while(sc.hasNext()){
- int [] vetor = new int [eventos];
- int [] vetorRank = new int [eventos];
- for (int i=1;i<eventos+1;i++) vetor[sc.nextInt()-1]=i;
- for (int i=0;i<eventos;i++) vetorRank[i]=hm.get(vetor[i]);
- for (int j=0;j<eventos;j++){
- backtracking(vetorRank,j,eventos);
- }
- System.out.println(notaMaxima);
- nota =1;
- notaMaxima=1;
- sc.nextLine();
- }
- sc.close();
- }
- public static void backtracking(int [] vetor, int posicao,int eventos){
- for (int i = posicao+1;i<eventos;i++){
- if(vetor[posicao]<vetor[i]){
- nota++;
- if (nota>notaMaxima) notaMaxima=nota;
- backtracking(vetor,i,eventos);
- nota--;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement