Help How To apply memoization to this DIGIT-DP Code

Revision en2, by taklo, 2019-06-13 20:42:58

I Have Tried the following problem using Digit DP please tell me how to apply memoization to it

--- Problem Link ---

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;
}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English taklo 2019-06-13 20:42:58 23
en1 English taklo 2019-06-13 20:42:09 862 Initial revision (published)