Advertisement
RaFiN_

digit dp

Mar 23rd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. ll giveres(int pos,int id,int lo,int hi,int flag,ll num){
  2.  
  3.     if(pos==(int)v.size()){
  4.  
  5.         if(flag){
  6.  
  7.             return 1;
  8.         }
  9.         else return 0;
  10.     }
  11.     ll &ret = dp[pos][id][lo][hi][flag];
  12.     if(ret!=-1)return ret;ret = 0;
  13.     int low,high;
  14.     if(lo)low = v[pos];
  15.     else low = 0;
  16.     if(hi)high = v2[pos];
  17.     else high = 9;
  18.     for(int i = low;i<=high;i++){
  19.         int state = id;
  20.         while(state!=-1&&!to[state][i])state = link[state];
  21.         if(state==-1)state = 0;
  22.         state = to[state][i];
  23.         ret+=giveres(pos+1,state,lo&(i==low),hi&(i==high),flag|(int)ending[state].size()>0,num*10+i);
  24.     }
  25.     return ret;
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement