Codeforces round #267 (Div. 2) B. Fedor and new game

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.