1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include<bits/stdc++.h> #define PII pair<int, LL> #define LL long long using namespace std; template <class T> inline void read(T &res) { res = 0; bool flag = 0; char c = getchar(); while(c < '0' || '9' < c) {if(c == '-') flag = 1; c = getchar();} while('0' <= c && c <= '9') res = (res << 3) + (res << 1) + (c ^ 48), c = getchar(); if(flag) res = -res; } template <class T, class ...ARC> inline void read(T &res, ARC &...com){ read(res), read(com...); } template <class T> void write(T res) { if(res < 0) putchar('-'), res = -res; if(res > 9) write(res / 10); putchar(res % 10 + '0'); } template <> inline void write(char c) { putchar(c); } template <> inline void write(char *s) { while(*s) putchar(*s ++);} template <class T, class ...ARC> inline void write(T res, ARC ...com) { write(res), write(com...); } const int N = 105, mod = 1e9 + 7; int n, b, k, x; struct Node{ int a[N][N]; Node operator* (Node b) { Node c; memset(c.a, 0, sizeof(c.a)); for(int i = 0;i < x;i ++) for(int j = 0;j < x;j ++) for(int k = 0;k < x;k ++) c.a[i][j] = (c.a[i][j] + 1ll * a[i][k] * b.a[k][j] % mod) % mod; return c; } }a; inline Node qpow(Node x, int k) { Node res = x; k --; while(k) { if(k & 1) res = res * x; k >>= 1; x = x * x; } return res; } int main() { read(n, b, k, x); for(int i = 1, v;i <= n;i ++) { read(v); for(int j = 0;j < x;j ++) a.a[j][(j * 10 + v) % x] ++; } a = qpow(a, b); write(a.a[0][k]); return 0; }
|