fork download
  1. #include <bits/stdc++.h>
  2. #include<ext/pb_ds/assoc_container.hpp>
  3. #include<ext/pb_ds/tree_policy.hpp>
  4.  
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7. typedef tree<int, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  8. typedef tree<int, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
  9.  
  10. void fileIO() {
  11.  
  12. #ifndef ONLINE_JUDGE
  13.  
  14. freopen("input.txt", "r", stdin);
  15. freopen("output.txt", "w", stdout);
  16.  
  17. #endif
  18.  
  19. }
  20.  
  21. void fastIO() {
  22.  
  23. ios_base::sync_with_stdio(false);
  24. cin.tie(nullptr);
  25. cout.tie(nullptr);
  26.  
  27. }
  28.  
  29. #define int ll
  30. typedef long long ll;
  31.  
  32. const int mod = 1e9 + 7, N = 1e5 + 1, OO = 1e18 + 5;
  33.  
  34. int arr[10][7] = {{1, 1, 1, 1, 1, 1, 0},
  35. {0, 1, 1, 0, 0, 0, 0},
  36. {1, 1, 0, 1, 1, 0, 1},
  37. {1, 1, 1, 1, 0, 0, 1},
  38. {0, 1, 1, 0, 0, 1, 1},
  39. {1, 0, 1, 1, 0, 1, 1},
  40. {1, 0, 1, 1, 1, 1, 1},
  41. {1, 1, 1, 0, 0, 0, 0},
  42. {1, 1, 1, 1, 1, 1, 1},
  43. {1, 1, 1, 1, 0, 1, 1},
  44. };
  45.  
  46. int n, x, y, tc = 1;
  47. string s1, s2;
  48.  
  49. bool dp[101][101][101];
  50. int vis[101][101][101];
  51.  
  52. bool fun(int idx, int rem_x, int rem_y){
  53. if(rem_x < 0 || rem_y < 0){
  54. return 0;
  55. }
  56. if(idx == n) {
  57. return 1;
  58. }
  59.  
  60. bool &ret = dp[idx][rem_x][rem_y];
  61. if(vis[idx][rem_x][rem_y] == tc) {
  62. return ret;
  63. }
  64. vis[idx][rem_x][rem_y] = tc;
  65.  
  66. bool ans = false;
  67. for (int target = 0; target <= 9; ++target) {
  68. int cnt_x = 0, cnt_y = 0;
  69. for (int i = 0; i < 7; ++i) {
  70. if(arr[s1[idx] - '0'][i] > arr[target][i]){
  71. cnt_x++;
  72. }
  73. if(arr[s1[idx] - '0'][i] < arr[target][i]){
  74. cnt_y++;
  75. }
  76.  
  77. if(arr[s2[idx] - '0'][i] > arr[target][i]){
  78. cnt_x++;
  79. }
  80. if(arr[s2[idx] - '0'][i] < arr[target][i]){
  81. cnt_y++;
  82. }
  83. }
  84.  
  85. ans |= fun(idx + 1, rem_x - cnt_x, rem_y - cnt_y);
  86. }
  87.  
  88. return ret = ans;
  89. }
  90.  
  91. void solve(){
  92. cin >> n >> x >> y;
  93. cin >> s1 >> s2;
  94. if(!fun(0, x, y)){
  95. cout << "NO\n";
  96. }
  97. else {
  98. cout << "YES\n";
  99. }
  100. }
  101.  
  102. signed main() {
  103. fileIO(); fastIO();
  104. int t = 1; cin >> t;
  105. while(t--){
  106. solve();
  107. tc++;
  108. }
  109. return 0;
  110. }
Success #stdin #stdout 0s 5300KB
stdin
Standard input is empty
stdout
YES