2048
Time Limit: 3000/1500 MS (Java/others) memory limit: 65536/65536 K (Java/Others)
Total submission (s): 566 accepted submission (s): 129
Problem descriptionteacher Mai is addicted to game 2048. But finally he finds it's too hard to get 2048. So he wants to change the rule:
You are given some numbers. Every time you can choose two numbers of the same value from them and merge these two numbers into their sum. And these two numbers disappear meanwhile.
If we can get 2048 from a set of numbers with this operation, teacher Mai think this Multiset is good.
You have n numbers, A1,..., An. Teacher Mai ask you how many subsequences of a are good.
The number can be very large and just output the number modulo 998244353.
Inputthere are multiple test cases, terminated by a line "0 ".
For each test case, the first line contains an integer N (1 <= n <= 10 ^ 5 ), the next line contains N integers AI (0 <= AI <= 2048 ).
Outputfor each test case, output one line "case # K: ANS", where k is the case number counting from 1, ANS is the number module 998244353.
Sample Input
41024 512 256 25641024 1024 1024 102451024 512 512 10
Sample output
Case #1: 1 case #2: 11 case #3: 8
Question: N numbers (0 ~ 2048). Calculate the number of a set that can be composed of these numbers and the sum of these numbers is 2048.
Idea: first, make sure that the number can constitute 2048, then these numbers can only be in the form of the X power of 2, so we can delete the number that is not a power of 2 first, it's okay to calculate the total number.
Now there is only the number of X power in the form of 2. It is easy to see that if the sum of a set is greater than or equal to 2048, in this collection, we can find a bunch of numbers to make up 2048.
In this way, we can find the number of sets whose sum is less than 2048, you can use DP [I] [J] to indicate that all the I-power numbers from 0 to 2 are selected, and the sum is in the I-power of [J * 2, (J + 1) x 2 I power) number of sets in the range,
The transfer equation is DP [I] [J] = DP [I] [J] + (DP [I-1] [(j-K) * 2] + dp [I-1] [(j-k) * 2 + 1]) * C (n, k ), where N is the number of I to the power of 2, K is the number of I to the power of 2 to be selected currently, apparently, the final answer is total-DP [11] [0],
Total indicates the number of sets that can be composed of all X power numbers, such as 2.
Finally, calculate the number of excluded items.