标签:des style http color io os ar for 2014
1 1 1 2 2 0 0 3 7 23 47 16
234 2799 72937Hint
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> typedef __int64 ll; using namespace std; const int maxn = 20; const int mod = 10000007; struct Matrix{ int n; ll v[maxn][maxn]; Matrix(int _n = maxn) { n = _n; } void init(ll _v = 0) { memset(v, 0, sizeof(v)); if (_v) for (int i = 0; i < n; i++) v[i][i] = _v; } void output() { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) printf("%I64d ", v[i][j]); puts(""); } puts(""); } } a, b, c; Matrix operator * (Matrix a, Matrix b) { Matrix c(a.n); for (int i = 0; i < a.n; i++) { for (int j = 0; j < a.n; j++) { c.v[i][j] = 0; for (int k = 0; k < a.n; k++) { c.v[i][j] += (a.v[i][k] * b.v[k][j]) % mod; c.v[i][j] %= mod; } } } return c; } Matrix operator ^ (Matrix a, ll k) { Matrix c(a.n); c.init(1); while (k) { if (k & 1) c = a * c; a = a * a; k >>= 1; } return c; } Matrix operator + (Matrix a, Matrix b) { Matrix c(a.n); for (int i = 0; i < a.n; i++) for (int j = 0; j < a.n; j++) c.v[i][j] = (b.v[i][j] + a.v[i][j]) % mod; return c; } Matrix operator + (Matrix a, ll b) { Matrix c = a; for (int i = 0; i < a.n; i++) c.v[i][i] = (a.v[i][i] + b) % mod; return c; } ll n, m, con[maxn]; ll f[maxn], f2[maxn]; int main() { while (scanf("%I64d%I64d", &n, &m) != EOF) { for (int i = 1; i <= n; i++) scanf("%I64d", &con[i]); memset(f, 0, sizeof(f)); f[0] = 233; f[1] = con[1]; for (int i = 2; i <= n; i++) { memcpy(f2, f, sizeof(f)); for (int j = 1; j < 10; j++) f[j] = f2[j] + f2[j-1]; f[i] = con[i]; f[0] = f[0] * 10 + 3; } a.init(); a.n = n + 2; a.v[0][0] = 10; a.v[0][n+1] = 1; for (int i = 1; i <= n; i++) a.v[i][i-1] = a.v[i][i] = 1; a.v[n+1][n+1] = 1; b.init(); b.n = n+2; for (int i = 0; i <= n; i++) b.v[i][0] = f[i]; b.v[n+1][0] = 3; c = a ^ m; c = c * b; printf("%I64d\n", c.v[n][0]); } return 0; }
标签:des style http color io os ar for 2014
原文地址:http://blog.csdn.net/u011345136/article/details/39275593