Hints for problem 431B — Shower Line

Revision en3, by SiddhyaRushLittlelordOP, 2023-07-20 18:18:03

Note: I'm unware whether I can ask question here. LMK if this post isn't suitable for guidelines. I'll delete it. ;-)

Hello, I'm having confusion about understanding the intuition behind the problem 431B — Shower Line.

I've read the problem statement and editorial it suggested this solution

Can anyone who has solved this problem please give me hint on how to come up with these arr[i][j] numbers in the loop

 do
    {
        //01234
        tmp = g[p[0]][p[1]] + g[p[1]][p[0]];
        tmp += g[p[2]][p[3]] + g[p[3]][p[2]];
        
        //1234
        tmp += g[p[1]][p[2]] + g[p[2]][p[1]];
        tmp += g[p[3]][p[4]] + g[p[4]][p[3]];
        
        //234
        tmp += g[p[2]][p[3]] + g[p[3]][p[2]];
        
        //34
        tmp += g[p[3]][p[4]] + g[p[4]][p[3]];
        
        if(tmp > ans)
        {
            ans = tmp;
            for(int i = 0 ; i < n ; ++i)
                pans[i] = p[i];
        }
    }
    while(next_permutation(p, p+n));

Thanks in advance :-)

Tags bruteforce, implementation, 1200, 431b

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English SiddhyaRushLittlelordOP 2023-07-20 18:18:03 6
en2 English SiddhyaRushLittlelordOP 2023-07-20 18:16:53 21
en1 English SiddhyaRushLittlelordOP 2023-07-20 18:16:27 1294 Initial revision (published)