设为首页 加入收藏

TOP

HDU - 5015 233 Matrix (矩阵构造)
2015-07-20 17:41:26 来源: 作者: 【 】 浏览:1
Tags:HDU 5015 233 Matrix 矩阵 构造
Problem Description In our daily life we often use 233 to express our feelings. Actually, we may say 2333, 23333, or 233333 ... in the same meaning. And here is the question: Suppose we have a matrix called 233 matrix. In the first line, it would be 233, 2333, 23333... (it means a 0,1 = 233,a 0,2 = 2333,a 0,3 = 23333...) Besides, in 233 matrix, we got a i,j = a i-1,j +a i,j-1( i,j ≠ 0). Now you have known a 1,0,a 2,0,...,a n,0, could you tell me a n,m in the 233 matrix?
Input There are multiple test cases. Please process till EOF.

For each case, the first line contains two postive integers n,m(n ≤ 10,m ≤ 10 9). The second line contains n integers, a 1,0,a 2,0,...,a n,0(0 ≤ a i,0 < 2 31).
Output For each case, output a n,m mod 10000007.
Sample Input
1 1
1
2 2
0 0
3 7
23 47 16

Sample Output
234
2799
72937

Hint

  
\

Source 2014 ACM/ICPC Asia Regional Xi"an Online
题意:求最后一位的值
思路:将第i行之后的矩阵都往后移动i位构造一个矩阵:
10 0 0 0 0 ... 1
1 1 0 0 0 ..... 0
0 1 1 0 ... 0
. . .. . .. . .. .. .. . .
0 0 0 0 0 .... 1,
但是还需要推出一个B维度为n+2 * 1的初始矩阵,就是根据移动的推出初始的一列
#include 
  
   
#include 
   
     #include 
    
      #include 
     
       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; }
     
    
   
  



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇HDU 5014 Number Sequence(2014 A.. 下一篇HDU - 5011 Game

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·MySQL 安装及连接-腾 (2025-12-25 06:20:28)
·MySQL的下载、安装、 (2025-12-25 06:20:26)
·MySQL 中文网:探索 (2025-12-25 06:20:23)
·Shell脚本:Linux Sh (2025-12-25 05:50:11)
·VMware虚拟机安装Lin (2025-12-25 05:50:08)