SiddhyaRushLittlelordOP's blog

By SiddhyaRushLittlelordOP, history, 16 months ago, In English

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 :-)

Full text and comments »