THEATRE - Editorial

Initially I thought that this is stable marriage problem with ties, did a bit of research but finally gave up.

Your solution fails for this test case-

1
24
A 12
A 9
A 9
A 9
B 12
B 12
B 9
B 9
B 9
B 9
C 12
C 12
C 3
C 3
C 3
C 6
C 6
D 3
D 3
D 3
D 3
D 6
D 6
D 6

Expected output-
825
825

Your programā€™s output-
925
925

Hope this helps

1 Like

If you donā€™t know the NQueens problem, Iā€™ll first advice you to study that and then try to understand my solution.

Try

Test case

1
4
A 6
C 6
C 6
C 9

2 Likes

Try

Test Case

1
2
B 9
D 9

1 Like

I am familiar the NQueens approach. I was finding difficult to understand your implementation. Which is why I asked if you could please elaborate a bitā€¦

WTF mahn!!! Respect = infinity;

when my code was long (according to noob me) I thought there ought to be some other solution and stopped coding.

Now I know what it takes for an AC;

Smart work is better than hard work :wink:

Should have done it easier but couldnā€™t think of any other solution

Oh! god, Silly Mistake! the ticket variable was to be reinitialized for every best_choice and I forgot about it. By the way thanks for your time.

Yeahā€¦I know .
I was pointing out your dedication.

1 Like

Oh, Thank you mate. One combination messed it up. AC now

I am only getting 30 points,can you fix it.

Can someone please provide a JAVA implementation of this, as in JAVA we donā€™t have any nextPermutation kinda function, so its becoming lil bit comlicated for me to go through, kindly help if any one can traslate the same implementation to simplest efficient JAVA codeā€¦

Thanks in advanceā€¦

can someone tell me where I am going wrong

https://www.codechef.com/viewsolution/29830163

Try this test case-

Test case

1
10
B 12
C 3
A 6
D 12
A 12
C 6
A 9
D 3
C 12
A 3

Ans- 250

1 Like

Try

Test case

1
4
A 12
A 9
B 6
C 9

Could you fix the link? It doesnā€™t point to any submission.

The recursive method works in pretty much every language and it is simple enough. Moreover, it can be easily extended (find all arrays with integers from 1 to n where each value can appear at most twice).

thanks a lot:+1::+1:

Can we use Hungarian Algorithm to solve this problem?