sanjay6969's blog

By sanjay6969, 4 weeks ago, In English

A network security company has an encryption algorithm which is used to encrypt and decrypt the company's sensitive data. The company wants to upgrade their decryption algorithm due to numerous cyber-attacks. Currently this new decryption algorithm is in the development phase, so the developers of the algorithm want to test it with the encrypted binary string. During the initial stage of the decryption process the new algorithm takes a list of binary strings consisting only of 0s and 1s and two integers X and Y. The decryption algorithm processes the list of binary strings in such a way that it displays the final decrypted message as the largest subset from the concatenated string which has at most X number of Os and at most Y number of 1s.

Write an algorithm for the decryption process to display the size of the largest subset which has at most X number of 0s and at most Y numbers of 1s.

Input The first line of the input consists of an integer- str_size, representing the total number of encrypted strings(N). The second line consists of N space-separated binary strings, representing the encrypted strings consisting only of 0s and 1s. The third line consists of an integer zeros_count, representing the maximum number of 0s in the decrypted message. The fourth line consists of an Integer ones_count, representing the maximum number of 1s in the decrypted message.

Output Print an integer representing the size of the largest subset which has at most X number of Os and at most Y number of 1s. Note A set A is a subset of another set B if all elements of A are also elements of B. A binary string is a string consisting of only 0s and 1s. The size of the largest subset is the total number of binary strings which are considered in the calculation of the final output.

Example
Input:
6
1 0 10 111 1100 1000
2
2

Output:
3
Explanation:
The largest subset with at most 2 0s and 2 1s are ("0", "1", '10"}, so the answer is 3.
  • Vote: I like it
  • -3
  • Vote: I do not like it

»
4 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

What is the maximum size of N and of the string? Get all the subsets using complete-search which has O(N!) complexity. And as a pre-processing step that can reduce the complexity a little bit when generating the subsets, you can count all 0's and 1's of each string and store them

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    that's I thought, it works fine. I think there are more optimised approach for this question, if you find it then do share.