#P3220. [HNOI2012] 与非
[HNOI2012] 与非
Description
NAND is a binary logical operation whose result is true if and only if the two input Boolean values are not both true. The truth table of the NAND operation is as follows (1 denotes true, 0 denotes false):

The NAND of two non-negative integers means writing them in binary and then applying the NAND operation bitwise on corresponding binary digits. Since the lengths of the two binary numbers may differ, we generally fix a most significant bit limit so that the binary representations of both numbers do not exceed bits; numbers shorter than bits are padded with leading zeros on the left.
Given non-negative integers and the designated bit-length , using NAND operations and parentheses, where each number may be used any number of times, please determine how many numbers in the range can be obtained.
Input Format
The first line contains four positive integers , , , and separated by spaces.
The second line contains non-negative integers , as described above.
Constraints: and , , .
Output Format
Output a single integer, the number of values in that can be computed.
3 3 1 4
3 4 5
4
Hint
In Sample 1, $(3 \text{ NAND } 4) \text{ NAND } (3 \text{ NAND } 5) = 1$, , and and can be obtained directly.
Translated by ChatGPT 5
京公网安备 11011102002149号