fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <stdio.h>
  4. #include <string>
  5. #include <set>
  6. #include <fstream>
  7. #include <algorithm>
  8. #include <math.h>
  9. #include <queue>
  10.  
  11. using namespace std;
  12.  
  13. int k, n, m, q, a[5000], w[12], sw;
  14.  
  15. int d[5000][1201];
  16.  
  17. int wu (int a, int b)
  18. {
  19. int sum = 0;
  20.  
  21. for (int i = 0; i < n; i++)
  22. {
  23. if (a % 2 == b % 2) sum += w[i];
  24.  
  25. a /= 2;
  26. b /= 2;
  27. }
  28.  
  29. return sum;
  30. }
  31.  
  32. int todc (string s)
  33. {
  34. int a = 0;
  35. for (int i = n - 1; i >= 0; i--)
  36. {
  37. a = a * 2 + s[i] - '0';
  38. }
  39.  
  40. return a;
  41. }
  42.  
  43. int main ()
  44. {
  45.  
  46. cin >> n >> m >> q;
  47.  
  48. char s[100], t[100];
  49.  
  50. for (int i = 0; i < n; i++)
  51. {
  52. cin >> w[i];
  53. sw += w[i];
  54. }
  55.  
  56. for (int i = 0; i < m; i++)
  57. {
  58. scanf ("%s", s);
  59.  
  60. a[todc (s)]++;
  61. }
  62.  
  63. for (int i = 0; i < (1 << n); i++)
  64. for (int j = 0; j < (1 << n); j++)
  65. {
  66. d[i][wu (i, j)] += a[j];
  67. }
  68.  
  69. for (int i = 0; i < (1 << n); i++)
  70. {
  71. for (int j = 1; j <= 1200; j++)
  72. d[i][j] += d[i][j-1];
  73. }
  74.  
  75. for (int i = 0; i < q; i++)
  76. {
  77. scanf ("%s %d", t, &k);
  78.  
  79. int f = todc (t);
  80.  
  81.  
  82. printf ("%d\n", d[f][k]);
  83. }
  84.  
  85. return 0;
  86. }
Success #stdin #stdout 0s 4356KB
stdin
Standard input is empty
stdout
Standard output is empty