【POJ 3233】Matrix Power Series】的更多相关文章

[题目链接] 点击打开链接 [算法] 要求 A^1 + A^2 + A^3 + ... + A^k 考虑通过二分来计算这个式子 : 令f(k) = A^1 + A^2 + A ^ 3 + ... + A^k 那么,当k为奇数时,f(k) = f(k-1) + A ^ k 当k为偶数时,f(k) = f(n/2) + A ^ (n/2) * f(n/2) 因此,可以通过二分 + 矩阵乘法快速幂的方式,在O(n^3log(n)^2)的时间内解决此题 [代码] #include <algorithm>…
Matrix Power Series Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 18450   Accepted: 7802 Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + - + Ak. Input The input contains exactly one test cas…
http://poj.org/problem?id=3233 (题目链接) 题意 给出一个n×n的矩阵A,求模m下A+A2+A3+…+Ak 的值 Solution 今日考试就A了这一道题.. 当k为偶数时,原式=(Ak2+1)×(A1+A2+...+Ak2). 当k为奇数的时候将Ak乘上当前答案后抠出去,最后统计答案时再加上.所以我们就一路快速幂搞过去,AC 代码 // poj3233 #include<algorithm> #include<iostream> #include&…
Matrix Descriptions 有一个N阶方阵 第i行,j列的值Aij =i2 + 100000 × i + j2 - 100000 × j + i × j,需要找出这个方阵的第M小值. Input 第一行输入T代表测试组数.每个测试用例包含2个数字N,M表示在N阶方阵找出第M大值, N(1 ≤ N ≤ 50,000) and M(1 ≤ M≤ N × N). 每两个测试用例之间可能有空行 Output 输出方阵的第M小值 Sample Input 12 1 1 2 1 2 2 2 3…
-->Matrix Descriptions: 输入一个n×n的矩阵,可以对矩阵的每行进行任意次的循环右移操作,行的每一次右移后,计算矩阵中每一列的和的最大值,输出这些最大值中的最小值. Sample Input 2 4 6 3 7 3 1 2 3 4 5 6 7 8 9 -1 Sample Output 11 15 题目链接 https://vjudge.net/problem/POJ-2078 使用dfs解决,对于n×n的矩阵来说,行循环右移后,矩阵最多有n^n中可能的状态,在这题中最多有7…
Matrix Power Series [题目链接]Matrix Power Series [题目类型]二分等比求和 &题解: 这题我原来用vector写的,总是超时,不知道为什么,之后就改用数组了,照着别人的代码敲了一遍 [时间复杂度]O(logn) &代码: #include <cstdio> #include <bitset> #include <iostream> #include <set> #include <cmath&g…
任意门:http://poj.org/problem?id=3233 Matrix Power Series Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 28619   Accepted: 11646 Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak. Input The…
poj 1575  Tr A 主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1575 题目大意:A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的和),现要求Tr(A^k)%9973. 数据的第一行是一个T,表示有T组数据. 每组数据的第一行有n(2 <= n <= 10)和k(2 <= k < 10^9)两个数据.接下来有n行,每行有n个数据,每一个数据的范围是[0,9].表示方阵A的内容. 一个矩阵高速幂的裸题. 题解: #…
Matrix Power Series Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 11954   Accepted: 5105 Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + … + Ak. Input The input contains exactly one test cas…
Matrix Power Series Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 15417   Accepted: 6602 Description Given a n × n matrix A and a positive integer k, find the sum S = A + A2 + A3 + - + Ak. Input The input contains exactly one test cas…