After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game? Call of soldiers 3 ?.
The game has (M? +? 1) players andNTypes of soldiers in total. players? Call of soldiers 3? Are Numbered form1 (M? +? 1). Types of soldiers are numbered from0N? -? 1. Each player has an army. Army ofI-Th player can be described by non-negative integerXI. Consider binary representationXI: IfJ-Th bit of numberXIEqual to one, then the army ofI-Th player has soldiers ofJ-Th type.
Fedor is (M? +? 1)-th player of the game. He assume that two players can become friends if their armies differ in at mostKTypes of soldiers (in other words, binary representations of the corresponding numbers differ in at mostKBITs). Help Fedor and count how many players can become his friends.
Input
The first line contains three IntegersN,M,K(1? ≤?K? ≤?N? ≤? 20; 1? ≤?M? ≤? 1000 ).
TheI-Th of the next (M? +? 1) lines contains a single integerXI(1? ≤?XI? ≤? 2N? -? 1), that describesI-Th player's army. We remind you that Fedor is (M? +? 1)-th player.
Output
Print a single integer-the number of fedor's potential friends.
Sample test (s) Input
7 3 18511117
Output
0
Input
3 3 31234
Output
3. Give you m + 1 to determine whether the binary form of the given number is smaller than or equal to k in number m + 1.#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 1010;int num[maxn], cnt;int main() {int n, m, k;scanf("%d%d%d", &n, &m, &k);for (int i = 0; i < m; i++)scanf("%d", &num[i]);scanf("%d", &cnt);int ans = 0;for (int i = 0; i < m; i++) {int cur = 0;for (int j = 0; j < n; j++)if (((1<<j)&num[i]) != ((1<<j)&cnt))cur++;if (cur <= k)ans++;}printf("%d\n", ans);return 0;}
Codeforces round #267 (Div. 2) B. Fedor and new game