矩阵快速幂。

题意事实上已经告诉我们这是一个矩阵乘法的运算过程。

构造矩阵:把xi列的bij都标为1.

例如样例二:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std; long long const MOD = ;
int n, m;
long long a[ + ]; struct Matrix
{
long long A[ + ][ + ];
int R, C;
Matrix operator*(Matrix b);
}; Matrix X, Y, Z; Matrix Matrix::operator*(Matrix b)
{
Matrix c;
memset(c.A, , sizeof(c.A));
int i, j, k;
for (i = ; i <= R; i++)
for (j = ; j <= b.C; j++)
for (k = ; k <= C; k++)
c.A[i][j] = (c.A[i][j] + (A[i][k] * b.A[k][j]) % MOD) % MOD;
c.R = R; c.C = b.C;
return c;
} void init()
{
memset(X.A, , sizeof X.A);
memset(Y.A, , sizeof Y.A);
memset(Z.A, , sizeof Z.A); Y.R = n; Y.C = n;
for (int i = ; i <= n; i++) Y.A[i][i] = ; X.R = n; X.C = n;
for (int j = ; j <= n; j++)
{
int xi; scanf("%d", &xi);
for (int i = ; i <= xi; i++)
{
int num; scanf("%d", &num); num++;
X.A[num][j] = ;
}
} Z.R = ; Z.C = n;
for (int i = ; i <= n; i++) Z.A[][i] = a[i]; } void read()
{
scanf("%d%d", &n, &m);
for (int i = ; i <= n; i++)
{
scanf("%lld", &a[i]);
a[i] = a[i] % MOD;
}
} void work()
{
while (m)
{
if (m % == ) Y = Y*X;
m = m >> ;
X = X*X;
}
Z = Z*Y; for (int i = ; i <= n; i++)
{
printf("%lld", Z.A[][i]);
if (i<n) printf(" ");
else printf("\n");
}
} int main()
{
int T;
scanf("%d", &T);
while (T--)
{
read();
init();
work();
}
return ;
}

UVA 11551 Experienced Endeavour的更多相关文章

  1. UVA 11551 - Experienced Endeavour(矩阵高速幂)

    UVA 11551 - Experienced Endeavour 题目链接 题意:给定一列数,每一个数相应一个变换.变换为原先数列一些位置相加起来的和,问r次变换后的序列是多少 思路:矩阵高速幂,要 ...

  2. UVA11551 Experienced Endeavour —— 矩阵快速幂

    题目链接:https://vjudge.net/problem/UVA-11551 题意: 给定一列数,每个数对应一个变换,变换为原先数列一些位置相加起来的和,问r次变换后的序列是多少 题解: 构造矩 ...

  3. F - Experienced Endeavour 矩阵快速幂

    Alice is given a list of integers by Bob and is asked to generate a new list where each element in t ...

  4. KUANGBIN带你飞

    KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //201 ...

  5. [kuangbin带你飞]专题1-23题目清单总结

    [kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...

  6. ACM--[kuangbin带你飞]--专题1-23

    专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...

  7. URAL 2089 Experienced coach Twosat

    Description Misha trains several ACM teams at the university. He is an experienced coach, and he doe ...

  8. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  9. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

随机推荐

  1. java基础增强

    Eclipse使用: java Compile配置的是java编译环境 java Build path配置的是java运行环境 运行环境的版本必须高于编译环境的版本.否则报错 工程上 右键--prop ...

  2. php 生成二维码 代码示例

    logo   是正方形  或者  圆形的   居多        <?php include ('phpqrcode.php'); $value = 'http://www.codesc.net ...

  3. NSAttributedString in Swift

    转载自: https://www.invasivecode.com/weblog/attributed-text-swift/   I have been talking quite a lot in ...

  4. BCDBOOT命令参数介绍

    BCDboot 命令行选项 更新时间: 2013年10月 应用到: Windows 8, Windows 8.1, Windows Server 2012, Windows Server 2012 R ...

  5. opencv鼠标操作及GUI矩形绘画

    OpenCV的鼠标操作是通过一个中介函数配合回调函数来实现的.指定鼠标操作消息回调函数的函数为SetMouseCallback. void setMouseCallback(const string& ...

  6. HDU1114--Piggy-Bank(完全背包变形)

    Piggy-Bank   Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  7. HDU2216:Game III(BFS)

    Game III Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Subm ...

  8. maven实战_测试覆盖率插件使用

    原文:http://www.cnblogs.com/yucongblog/p/5297051.html 1.环境准备 <project> ... <reporting> < ...

  9. PAT1027

    People in Mars represent the colors in their computers in a similar way as the Earth people. 火星人在他们的 ...

  10. 设置自己Eclipse代码风格(内部)

    http://www.cnblogs.com/farseer810/p/4391318.html 经过这几次的代码提交,发现很多人的代码风格不够规范.个人认为很有必要强制性规定一下代码的规范. 整体来 ...