F - Experienced Endeavour 矩阵快速幂
Alice is given a list of integers by Bob and is asked to generate a new list where each element in the new list is the sum of some other integers in the original list. The task is slightly more involved, as Bob also asks Alice to repeat this several times before giving him the result. Help Alice automate her task. Input The first line of the input is t (1 ≤ t ≤ 10), the number of cases to follow. Each case is in the following format: n r a0 a1 . . . an−1 x0 b0,0 b0,1 . . . b0,x0−1 x1 b1,0 b1,1 . . . b1,x1−1 . . . xn−1 bn−1,0 bn−1,1 . . . bn−1,xn−1−1 Each case begins with the integer n (1 ≤ n ≤ 50), which is the number of elements in the list of integers that Alice is given. The integer r (1 ≤ r ≤ 109 ) is the number of times these operations are to be repeated on a list before returning the result. The values are the nonnegative integers in the original list. Then n lines follow that define how Alice will generate a new list from a previous one. Each of these lines are in the form: xi bi,0 bi,1 . . . b1,xi This line defines the value of the i-th element in the new list to be the sum of elements: abi,0 , abi,1 , . . . , ab1,xi−1 Output The output consists of t lines, one line for each test case listing the final list of integers modulo 1000 in the form: c0 c1 . . . cn−1 Sample Input 2 2 2 1 2 2 0 1 1 1 2 4 507 692 2 0 1 1 1 Sample Output 5 2 275 692
- #include<iostream>
- #include<cstdio>
- #include<cmath>
- #include<cstring>
- #include<algorithm>
- #include<queue>
- #include<vector>
- #include<cmath>
- #include<map>
- #include<stack>
- #include<set>
- #include<string>
- using namespace std;
- typedef long long LL;
- typedef unsigned long long ULL;
- #define MAXN 51
- #define MOD 10000007
- #define INF 1000000009
- const double eps = 1e-;
- /*
- 矩阵快速幂 列出状态转移方程
- 这个题读了半天...
- */
- int T, n, k;
- int l[MAXN],res[MAXN];
- struct Mat
- {
- int a[MAXN][MAXN];
- Mat()
- {
- memset(a, , sizeof(a));
- }
- Mat operator* (const Mat& rhs)const
- {
- Mat ans;
- for (int i = ; i < n; i++)
- {
- for (int j = ; j < n; j++)
- {
- for (int t = ; t < n; t++)
- ans.a[i][j] = (ans.a[i][j] + a[i][t] * rhs.a[t][j]) % ;
- }
- }
- return ans;
- }
- };
- Mat fpow(Mat m, int b)
- {
- if (b <= ) return m;
- Mat ans;
- for (int i = ; i < n; i++)
- ans.a[i][i] = ;
- while (b != )
- {
- if (b & )
- ans = m*ans;
- m = m * m;
- b = b / ;
- }
- return ans;
- }
- int main()
- {
- scanf("%d", &T);
- while (T--)
- {
- scanf("%d%d", &n, &k);
- for (int i = ; i < n; i++)
- scanf("%d", &l[i]);
- Mat M;
- int x, tmp;
- for (int i = ; i < n; i++)
- {
- scanf("%d", &x);
- while (x--)
- {
- scanf("%d", &tmp);
- M.a[i][tmp] = ;
- }
- }
- M = fpow(M, k );
- memset(res, , sizeof(res));
- for (int i = ; i < n; i++)
- {
- for (int j = ; j < n; j++)
- {
- res[i] = (res[i] + M.a[i][j] * l[j])%;
- }
- }
- for (int i = ; i < n; i++)
- {
- if (i) printf(" ");
- printf("%d", res[i]);
- }
- printf("\n");
- }
- }
F - Experienced Endeavour 矩阵快速幂的更多相关文章
- UVA11551 Experienced Endeavour —— 矩阵快速幂
题目链接:https://vjudge.net/problem/UVA-11551 题意: 给定一列数,每个数对应一个变换,变换为原先数列一些位置相加起来的和,问r次变换后的序列是多少 题解: 构造矩 ...
- UVA 11551 - Experienced Endeavour(矩阵高速幂)
UVA 11551 - Experienced Endeavour 题目链接 题意:给定一列数,每一个数相应一个变换.变换为原先数列一些位置相加起来的和,问r次变换后的序列是多少 思路:矩阵高速幂,要 ...
- uva 10518 - How Many Calls?(矩阵快速幂)
题目链接:uva 10518 - How Many Calls? 公式f(n) = 2 * F(n) - 1, F(n)用矩阵快速幂求. #include <stdio.h> #inclu ...
- POJ 3070 Fibonacci 矩阵快速幂模板
Fibonacci Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18607 Accepted: 12920 Descr ...
- 【模板】矩阵快速幂 洛谷P2233 [HNOI2002]公交车路线
P2233 [HNOI2002]公交车路线 题目背景 在长沙城新建的环城公路上一共有8个公交站,分别为A.B.C.D.E.F.G.H.公共汽车只能够在相邻的两个公交站之间运行,因此你从某一个公交站到另 ...
- hdu 2842 Chinese Rings 矩阵快速幂
分析: 后面的环能不能取下来与前面的环有关,前面的环不被后面的环所影响.所以先取最后面的环 设状态F(n)表示n个环全部取下来的最少步数 先取第n个环,就得使1~n-2个环属于被取下来的状态,第n-1 ...
- 斐波那契数列第N项f(N)[矩阵快速幂]
矩阵快速幂 定义矩阵A(m*n),B(p*q),A*B有意义当且仅当n=p.即A的列数等于B的行数. 且C=A*B,C(m*q). 例如: 进入正题,由于现在全国卷高考不考矩阵,也没多大了解.因为遇到 ...
- Codeforces Round #536 (Div. 2) F 矩阵快速幂 + bsgs(新坑) + exgcd(新坑) + 欧拉降幂
https://codeforces.com/contest/1106/problem/F 题意 数列公式为\(f_i=(f^{b_1}_{i-1}*f^{b_2}_{i-2}*...*f^{b_k} ...
- HDU 1005 Number Sequence【斐波那契数列/循环节找规律/矩阵快速幂/求(A * f(n - 1) + B * f(n - 2)) mod 7】
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- GIt学习之路 第二天 创建版本库
本文参考廖雪峰老师的博客进行总结,完整学习请转廖雪峰博客 创建版本库 阅读: 1859216 什么是版本库呢?版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文 ...
- KMP POJ 2406 Power Strings
题目传送门 /* 题意:一个串有字串重复n次产生,求最大的n KMP:nex[]的性质应用,感觉对nex加深了理解 */ /************************************** ...
- 题解报告:hdu 1686 Oulipo(裸KMP)
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- AppConfig 操作简易封装
using System; using System.Configuration; namespace HT.IMS.Common { public class ClientConfig { ; pu ...
- 在计算机视觉与人工智能领域,顶级会议比SCI更重要(内容转)
很多领域,SCI是王道,尤其在中国,在教师科研职称评审和学生毕业条件中都对SCI极为重视,而会议则充当了补充者的身份.但是在计算机领域,尤其是人工智能与机器学习领域里,往往研究者们更加青睐于会议 我无 ...
- MVC之参数验证(三)
在实际开发中,项目经理会一直强调一句话,永远不要相信客户端的数据(前端可以不用验证,但是后端必须验证).大家同意这样的说法吧..新端验证毋庸质疑JS验证,提高用户体验我们不得不添加一些与后端一致的验证 ...
- 前端--3、JavaScript
引入方式: 直接在HTML中写入(了解) 写到文件中引入 声明变量 变量赋值方式 单个变量赋值 多变量的变量赋值 数据类型 数字and字符串 boolean undefined 数据类型的存储 数组 ...
- 简单的css缩放动画,仿腾讯新闻的分享按钮和美团app底部的图标样式
最近看到一些好看的hover的图形缩放效果.然后自己就写了下,发现这2种效果都不错.如果伙伴们更好的实现方式可以在下面留言哦~ 还有美团的效果,我就不展示了,喜欢的可以去app应用上看看. 这两种效果 ...
- SQL SERVER 执行计划各字段注释
SET SHOWPLAN_ALL使 Microsoft® SQL Server™ 不执行 Transact-SQL 语句.相反,SQL Server 返回有关语句执行方式和语句预计所需资源的详细信息. ...
- Windows提高_1.3文件操作
文件操作 不带句柄的文件操作 // 1. 拷贝文件,第三个参数为 FALSE 表示会覆盖 // CopyFile(L"D:\\1.txt", L"E:\\2.txt&qu ...