Help How To apply memoization to this DIGIT-DP Code

Правка en1, от taklo, 2019-06-13 20:42:09

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

--- Problem Link --- ~~~~~

include

include

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

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский taklo 2019-06-13 20:42:58 23
en1 Английский taklo 2019-06-13 20:42:09 862 Initial revision (published)