Advertisement
Josif_tepe

Untitled

Dec 8th, 2021
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int dp[200005][8];
  5. int n;
  6. string s;
  7. int module=1000000007;
  8. int rec(int i, int remainder){
  9.     if((i==n)and(remainder==0)){
  10.         return(1);
  11. }
  12.         if(i==n){
  13.         return(0);
  14.     }
  15.  
  16.  
  17.     if(dp[i][remainder]!=-1){
  18.         return(dp[i][remainder]);
  19.         }
  20.  
  21.    int result=0;
  22.  
  23.    result+=rec(i+1, remainder);
  24.    result+=rec(i+1, (remainder*10+(s[i]-'0'))%8);
  25.    result%=module;
  26.  
  27.    dp[i][remainder]=result;
  28.    return(result);
  29. }
  30. int main()
  31. {
  32.  
  33. cin>>n;
  34.  
  35. cin>>s;
  36.  
  37. for(int i=0; i<n; i++){
  38.     for(int j=0; j<8; j++){
  39.         dp[i][j]=-1;
  40.     }
  41. }
  42. cout<<rec(0, 0)-1;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement