Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int n;
- string a;
- int memo[200000][8];
- int f(int i,int remainder){
- if(i == n && remainder == 0){
- return 1;
- }
- if(i == n && remainder != 0){
- return 0;
- }
- if(memo[i][remainder] != -1 ){
- return memo[i][remainder];
- }
- int res = 0;
- int mod = 1e9 +7;
- res += f(i+1,remainder)+ f(i+1,((remainder*10 + (a[i]-'0'))%8));
- res %= mod;
- return memo[i][remainder] = res;
- }
- int main() {
- cin >>n;
- cin >>a;
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < 8; j++) {
- memo[i][j] = -1;
- }
- }
- cout << f(0,0) -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement