I Have Tried the following problem using Digit DP please tell me how to apply memoization to it
Your code here...
#include<iostream>
#include<vector>
#define Mod 1000000007
#define ll long long
using namespace std;
int a,b,n;
bool check_good(int digit_sum){
bool res=1;
while(digit_sum>0){
if(digit_sum%10!=a && digit_sum%10!=b){
res=0;
break;
}
digit_sum/=10;
}
return res;
}
vector<int > num;
ll call(int pos,int digit_sum){
if(pos==n){
if(check_good(digit_sum)){
return 1;
}
else{
return 0;
}
}
ll ans=0;
ans=(ans+call(pos+1,digit_sum+a))%Mod;
ans=(ans+call(pos+1,digit_sum+b))%Mod;
return ans;
}
int main(){
cin>>a>>b>>n;
cout<<call(0,0);
return 0;
}