Ask a Question

 

Start Coding Today

   

GeeksQuiz

GeeksforGeeksIDE

Data Structures

Algorithms

Interview Experiences

C Programming

C++ Programming

Java Programming

GATE CS

Books

Please explain me this code

#include <iostream>
#include<cstring>
using namespace std;
const unsigned int M = 1000000007;
long long int len,dp[200000][8];
char *ar;
long long int fun(int idx,int m)
{
    if(idx==len)                        
        return (m==0);                    
    if(dp[idx][m]!=-1)
        return (dp[idx][m]);
    long long int ans=fun(idx+1,m)%M;                
    ans+=(fun(idx+1,(m*10+(ar[idx]-'0'))%8))%M;    
    return dp[idx][m]=(ans);
}
int main()
{
cin>>len;
ar=(char *)malloc((len+1));
    cin>>ar;
    memset(dp,-1,sizeof(dp));
    cout<<(fun(0,0)-1)%M;            
    return 0;
}

It finds the number of susequences of a number divisible by 8

But what is the algorithm? 

asked Jan 19 by anonymous

Please log in or register to answer this question.

...