i have solved this problem without using backtracking, and getting the correct answer. But on submission , its showing wrong answer.
Here’s my code :
#include<bits/stdc++.h>
using namespace std;
// int count = 0;
int class_Assign (int ans, int n, char prev) {
if (ans == n) {
// cout << out << endl;
// count++;
return 1;
}
int count = 0;
//rec
if (prev == ‘a’) {
count += class_Assign (ans+1, n, ‘a’) + class_Assign (ans + 1, n, ‘b’);
}
else {
count += class_Assign (ans + 1, n, ‘a’);
}
return count;
}
int main() {
int t;
cin >> t;
while (t–) {
int n;
cin >> n;
cout << “#” << n << " : " <<class_Assign (0, n, ‘a’) << endl;
}
return 0;
}