HDU 5015 233 Matrix(西安网络赛I题)

HDU 5015 233 Matrix

题目链接

思路:矩阵快速幂,观察没一列,第一个和为左边加最上面,第二个可以拆为左边2个加最上面,第三个可以拆为为左边3个加最上面,这样其实只要把每一列和每一列右边那列的233构造出一个矩阵,进行矩阵快速幂即可

代码:

#include <cstdio>
#include <cstring>

typedef long long ll;
const int N = 15;
const int MOD = 10000007;

int n, m;

struct mat {
	ll v[N][N];
	mat() {memset(v, 0, sizeof(v));}
	mat operator * (mat c) {
		mat ans;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				for (int k = 0; k < n; k++)
					ans.v[i][j] = (ans.v[i][j] + v[i][k] * c.v[k][j] % MOD) % MOD;
		return ans;
	}
};

mat pow_mod(mat x, int k) {
	mat ans;
	for (int i = 0; i < n; i++)
		ans.v[i][i] = 1;
	while (k) {
		if (k&1) ans = ans * x;
		x = x * x;
		k >>= 1;
	}
	return ans;
}

int main() {
	while (~scanf("%d%d", &n, &m)) {
		mat A;
		A.v[0][0] = 1;
		A.v[1][0] = 1; A.v[1][1] = 10;
		n += 2;
		for (int i = 2; i < n; i++) {
			for (int j = 1; j <= i; j++)
				A.v[i][j] = 1;
		}
		A = pow_mod(A, m);
		ll ans = 0;
		ll tmp[N];
		tmp[0] = 3; tmp[1] = 233;
		for (int i = 2; i < n; i++)
			scanf("%I64d", &tmp[i]);
		for (int i = 0; i < n; i++)
			ans = (ans + tmp[i] * A.v[n - 1][i] % MOD) % MOD;
		printf("%I64d\n", ans);
	}
	return 0;
}
时间: 2024-08-07 04:22:33

HDU 5015 233 Matrix(西安网络赛I题)的相关文章

HDU 5011 Game(西安网络赛E题)

HDU 5011 Game 题目链接 思路:其实就求一个Nim和即可,要推也不难推,和为0下一个必然是胜态,因为至少取走一个,在怎么分也达不到原来那个值了,如果是非0值,就和原来Nim一样必然可以取一堆使得变成0 代码: #include <cstdio> #include <cstring> const int N = 100005; int n; long long a, sum; int main() { while (~scanf("%d", &

HDU 5017 Ellipsoid(西安网络赛K题)

HDU 5017 Ellipsoid 题目链接 思路:模拟退火大法好! 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int D[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}}; dou

hdu 5015 233 Matrix (矩阵高速幂)

233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 749    Accepted Submission(s): 453 Problem Description In our daily life we often use 233 to express our feelings. Actually, we may s

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

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

hdu 5015 233 Matrix

233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 392    Accepted Submission(s): 262 Problem Description In our daily life we often use 233 to express our feelings. Actually, we may s

HDU 5008西安网络赛B题:后缀数组求第k小子串

思路:尼玛,这题搞了一天了,比赛的时候用了n^2的方法绝对T了,然后今天看别人代码看了一天才知道.后面感觉也挺容易的,就是没想到,之前做过SPOJ 694 705求过不同子串了,知道怎么求不同子串个数了,但是比赛的时候这个技巧竟然抛在脑后了,然后就不会了. 但是今天自己用了自己的两个后缀数组的模板(倍增和DC3)的都WA了,搞得自己真想跳楼去了!! 到现在都不知道到底是哪里错了,处理的方法和标准做法都一样,但是就是WA,然后用了别人的模板,再用自己的处理方法就过了,怀疑自己的两个模板是不是哪里错

hdu 5015 233 Matrix(最快的搞法)

233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 191    Accepted Submission(s): 125 Problem Description In our daily life we often use 233 to express our feelings. Actually, we may s

hdu 5015 233 Matrix (矩阵快速幂)

233 Matrix Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 749    Accepted Submission(s): 453 Problem Description In our daily life we often use 233 to express our feelings. Actually, we may s