矩阵快速幂。

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

构造矩阵:把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. CDockablePane 关闭的问题

    显示或者隐藏 当点击CDockablePane上的关闭按钮时,并不能将其关闭,知识将其隐藏了起来,如果需要重新显示或隐藏,则相关命令的响应函数如下: if(m_Panes.GetSafeHwnd()) ...

  2. Mac机上安装虚拟机

    1.首先要下载虚拟机VMware.网址http://pan.baidu.com/share/init?shareid=1519279671&uk=1434905687,连接该网址,下载里边的这 ...

  3. android TextView 之探究

    1:插入图片替换 //代码 mSubjectDetailView = (TextView) findViewById(R.id.subject_detail); CharSequence text = ...

  4. Problem H: 小火山的围棋梦想 多校训练2(小火山专场)

    题目链接:http://acm.zzuli.edu.cn/zzuliacm/problem.php?id=1908 题意:如果'.'被'*'围起来,就把'.'变为'*'. 分析:如果是'*'直接输出, ...

  5. HDU 5718 Oracle

    如果非零的数小于等于1个,则无解.否则有解. 取出一个最小的非零的数作为一个数,剩下的作为一个数,相加即可. #include<cstdio> #include<cstring> ...

  6. The Importance of Money in Life

    What were you taught about money as you were growing up?something like "Money doesn't grow on t ...

  7. nginx多域名配置

    方法一:多个.conf方法(优点是灵活,缺点就是站点比较多配置起来麻烦) 这里以配置2个站点(2个域名)为例,n 个站点可以相应增加调整,假设: IP地址: 192.168.1.100域名1 exam ...

  8. 任意2个io直接驱动LCD1602,并且不需外加芯片(转)

    http://www.amobbs.com/thread-4301955-1-1.html *此处只摘录部分内容,详细内容请关注原贴. 这就是电路,细心的朋友会发现实物图中有几个贴片的阻容件,秘密就在 ...

  9. C++ Builder string相互转换(转)

    源:http://www.cnblogs.com/zhcncn/archive/2013/05/20/3089084.html 1. char*->string (1)直接转换 const ch ...

  10. P8 Visible Lattice Points

    P8 Visible Lattice Points Time Limit:1000ms,     Memory Limit:65536KB Description A lattice point (x ...