|
| 1 | +#include <cstdio> |
| 2 | + |
| 3 | +const int MAX_BITS = 100 + 4; |
| 4 | +int total_strings[MAX_BITS][MAX_BITS] = {0}; |
| 5 | + |
| 6 | +void precompute() |
| 7 | +{ |
| 8 | + int no_of_strings[MAX_BITS][MAX_BITS][2] = {0}; |
| 9 | + const int ZERO_FIRST = 0, ONE_FIRST = 1; |
| 10 | + |
| 11 | + no_of_strings[1][0][ZERO_FIRST] = 1, no_of_strings[1][0][ONE_FIRST] = 1, total_strings[1][0] = 1 + 1; |
| 12 | + no_of_strings[1][1][ZERO_FIRST] = 0, no_of_strings[1][1][ONE_FIRST] = 0, total_strings[1][1] = 0 + 0; |
| 13 | + |
| 14 | + for(int i = 2; i < MAX_BITS; i++) |
| 15 | + { |
| 16 | + no_of_strings[i][0][ZERO_FIRST] = total_strings[i - 1][0]; |
| 17 | + no_of_strings[i][0][ONE_FIRST] = no_of_strings[i - 1][0][ZERO_FIRST]; |
| 18 | + total_strings[i][0] = no_of_strings[i][0][ZERO_FIRST] + no_of_strings[i][0][ONE_FIRST]; |
| 19 | + |
| 20 | + for(int set_bits = 1; set_bits < i; set_bits++) |
| 21 | + { |
| 22 | + no_of_strings[i][set_bits][ZERO_FIRST] = total_strings[i - 1][set_bits]; |
| 23 | + no_of_strings[i][set_bits][ONE_FIRST] = no_of_strings[i - 1][set_bits][ZERO_FIRST] + no_of_strings[i - 1][set_bits - 1][ONE_FIRST]; |
| 24 | + |
| 25 | + total_strings[i][set_bits] = no_of_strings[i][set_bits][ZERO_FIRST] + no_of_strings[i][set_bits][ONE_FIRST]; |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +int main() |
| 31 | +{ |
| 32 | + precompute(); |
| 33 | + |
| 34 | + int no_of_test_cases; |
| 35 | + scanf("%d", &no_of_test_cases); |
| 36 | + |
| 37 | + while(no_of_test_cases--) |
| 38 | + { |
| 39 | + int test_i, no_of_bits, no_of_set_bits; |
| 40 | + scanf("%d %d %d", &test_i, &no_of_bits, &no_of_set_bits); |
| 41 | + printf("%d %d\n", test_i, total_strings[no_of_bits][no_of_set_bits]); |
| 42 | + } |
| 43 | + |
| 44 | + return 0; |
| 45 | +} |
0 commit comments