Editorial for COCI '15 Contest 6 #4 Parovi
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Let's denote the family of sets that have the partition located at index
Then the solution is all sets from
The inclusion-exclusion principle provides us with an efficient way of calculating the size of the solution set. It holds:
In order to calculate the cardinality of the required intersection, we need to count how many pairings such that the partitions are located at
That number is equal to
Please note: A solution using dynamic programming also exists and is left as an exercise to the reader.
Comments