AtCoder Quality Problem
Time limit2sMemory limit512 MB
Given costs to paint each of the 2^n subsets red or blue, find the minimum total cost so that the union of any two same-colored subsets has that same color.
- Level
Hard9 of 10
- Topics
- Bit manipulation, Graph, Dynamic programming
- Solved
- No attempts yet
Statement
You have a set of elements. You want to paint each subset of either red or blue. For each subset of , the cost to paint it red is , and the cost to paint it blue is .
Note: you paint subsets, not the elements.
There is one requirement:
- If and are two subsets of the same color, then the subset has the same color as and .
Find the minimum total cost to paint all subsets.
Input
The first line contains a single integer (), the number of elements.
The second line contains integers (), the costs to paint subsets red.
The third line contains integers (), the costs to paint subsets blue.
Subset () consists of the elements for which the -th bit in the binary representation of is 1.
Output
Print one integer: the minimum cost to paint all subsets.