All Pairs Similarity
Time limit2sMemory limit2048 MB
Given N bitstrings of length K, output for each cow the sum of its Jaccard similarities with all N bitstrings, including its own, modulo 10^9+7.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Dynamic programming, Math
- Solved
- No attempts yet
Problem
Farmer John has cows (), and each cow is assigned a bitstring of length that is not all zero (). Different cows may be assigned the same bitstring. The Jaccard similarity of two bitstrings is the number of set bits in their bitwise intersection divided by the number of set bits in their bitwise union. For example, the Jaccard similarity of the bitstrings 11001 and 11010 is . For each cow, output the sum of her bitstring's Jaccard similarity with the bitstrings of all cows, including her own, modulo . If the sum equals a rational number with and coprime, output the unique integer in such that is divisible by .
Input
The first line contains and . Each of the next lines contains an integer , which represents the cow's bitstring as the length- binary representation of .
Output
Output the sum modulo for each cow on a separate line.
Hint
The cows are assigned the bitstrings 01, 01, 10, and 11. For the first cow, the sum is . The second cow has the same bitstring as the first cow, so her sum is the same. For the third cow, the sum is .