What data structure can I occupy in my problem? (acm 2014 Baggage)


the problem is to order an array that contains 2n pairs of letters of the form BA but can not be ordered in an ordinary way, it has to be ordered by moving block from to 2 (I can not move just one letter)

example n = 4: BABABABA

    public void emparejarAAyBB(int pos){ // pos = posicion a remplazar
    System.out.println("PAREJA AB");
    int bloqueAux = tomarUltimoAB();
    System.out.println("PAREJA BA");
    int aux2 = tomarPrimerBA();
    if(tomarUltimoAB()!=-1){        // si hay otro bloque AB que cumpla los requisitos se repite el ciclo

I tried to find a pattern when ordering but I could not do it. Now I think to solve it by brute force, I realized that in every step there are always n possible movements and that the minimum number of movements is n. So there would be possible paths which I do not know how to save them.

asked by Cristian Figueroa 23.11.2018 в 17:08

0 answers