BitStrings
SRM 248 · 2005-06-21 · by NeverMore
Problem Statement
Create a class BitStrings that contains a method maxStrings. maxStrings takes a
Constraints
- list will contain between 2 and 20 elements inclusive.
- Each element of list will have a length between 1 and 50 inclusive.
- Each element of list will contain only the characters '0' and '1'.
- numZeroes and numOnes will each be between 0 and 500 inclusive.
{"1", "00", "100"}
3
1
Returns: 2
Here, you have three 0's and one 1 at your disposal. The best you can do is create the first two bitstrings. Note that if you create the third bitstring, then you cannot construct any other bitstrings because you won't have a sufficient number of 0's and 1's.
{"00", "110", "101"}
2
4
Returns: 2
In this case, you have 2 0's and 4 1's. Although you can make the first bitstring "00", you then run out of zeroes and cannot make any more; in this case, you can only construct 1 bitstring. You can do better if you leave the first bitstring and construct the last two, giving a final answer of 2.
{"111", "01", "11", "10", "101"}
3
9
Returns: 5
{"00", "000", "00000"}
0
100
Returns: 0
{"110", "01", "1101", "00"}
2
3
Returns: 2
Submissions are judged against all 47 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class BitStrings with a public method int maxStrings(vector<string> list, int numZeroes, int numOnes) · 47 test cases · 2 s / 256 MB per case