#include <iostream>
#include <vector>
//回溯暴力搜索
void backTracking(int& ans, int i, int j, int k, const int& n, const int& A, const int& B, const std::vector<int>& array_a){
if(i >= n){
if(j % 10 == A && k % 10 == B){
ans++;
}else if(j == 0 && k % 10 == B || k == 0 && j % 10 == A){
ans++;
}
return;
}
backTracking(ans, i + 1, j + array_a[i], k, n, A, B,array_a);
backTracking(ans, i + 1, j , k+ array_a[i], n, A, B,array_a);
}
int solution(int n, int A, int B, std::vector<int> array_a) {
// Please write your code here
int ans = 0;
backTracking(ans, 0, 0, 0, n, A, B, array_a);
return ans;
}
int main() {
// You can add more test cases here
std::vector<int> array1 = {1, 1, 1};
std::vector<int> array2 = {1, 1, 1};
std::vector<int> array3 = {1, 1};
std::cout << (solution(3, 1, 2, array1) == 3) << std::endl;
std::cout << (solution(3, 3, 5, array2) == 1) << std::endl;
std::cout << (solution(2, 1, 1, array3) == 2) << std::endl;
return 0;
}
两种情况选或者不选