fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int MOD = 1000000007;
  4.  
  5. int B;
  6. string Y;
  7. int memo[100001];
  8.  
  9. int DP(int now) {
  10. if(now == Y.size()) return 1;
  11. if(memo[now] != -1) return memo[now];
  12. int running = Y[now]-'0', ans = 0;
  13. if(running == 0)
  14. return memo[now] = DP(now+1);
  15. for(int i = 1; running < B && now+i <= Y.size(); i++) {
  16. ans = (ans+DP(now+i))%MOD;
  17. running = running*10 + (Y[now+i]-'0');
  18. // cout << running << " ";
  19. }
  20. return memo[now] = ans;
  21. }
  22.  
  23. int main() {
  24. while(cin >> B >> Y) {
  25. memset(memo, -1, sizeof(memo));
  26. // check validity
  27. cout << DP(0) << endl;
  28. /*
  29. for(int i = 0; i < Y.size(); i++)
  30. cout << memo[i] << " ";
  31. cout << endl;
  32. /**/
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 5324KB
stdin
1000000
123456789123456789123456789123456789
stdout
649774399