// Problem: 1586:【 例 2】数字游戏 // Contest: SSOIER // URL: http://ybt.ssoier.cn:8088/problem_show.php?pid=1586 // Memory Limit: 524 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h> usingnamespace std; #define int long long inlineintread(){int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+ (x<<3)+(ch^48);ch=getchar();}return x*f;} //#define M #define mo 1000000007 //#define N int n, m, i, j, k; int x, y, a[30], ten[10010]; int f[30][10][10][2]; int s[30][10][10][2]; int t[30][10][10][2];
intdfs(int n, int sum, int x, int p) { if(n==0) return f[n][sum][x][p]=((sum%7>0 && x%7>0) ? 1 : 0); int i, k=0, F, S, T; if(f[n][sum][x][p]!=-1) return f[n][sum][x][p]; for(i=0; i<=9; ++i) { if(!p && i>a[n]) break; if(i==7) continue; k+=dfs(n-1, (sum+i)%7, (x*10+i)%7, p|(i<a[n])); k%=mo; F=f[n-1][(sum+i)%7][(x*10+i)%7][p|(i<a[n])]; S=s[n-1][(sum+i)%7][(x*10+i)%7][p|(i<a[n])]; T=t[n-1][(sum+i)%7][(x*10+i)%7][p|(i<a[n])]; t[n][sum][x][p]+=(ten[n-1]*i%mo*F%mo+T)%mo; // printf("t[%lld][%lld][%lld][%lld]+=ten[%lld]*%lld*%lld+%lld\n", n, sum, x, p, n-1, i, F, T); s[n][sum][x][p]+=(ten[n-1]*ten[n-1]%mo*i%mo*i%mo*F%mo+ten[n-1]*i%mo*T%mo*2%mo+S)%mo; // printf("%lld %lld %lld %lld\n", n, S, T, s[n][sum][x][p]); t[n][sum][x][p]%=mo; s[n][sum][x][p]%=mo; } return f[n][sum][x][p]=k; }