矩阵 uva 12037
来源:互联网 发布:3w咖啡盈利模式 知乎 编辑:程序博客网 时间:2024/06/05 04:11
自动机构造矩阵 注意初值与解状态取舍
#include <stdio.h>#include <iostream>using namespace std;const int mod = 34830;const int maxn = 10;typedef long long ll;int n,k;struct mat{ ll e[maxn][maxn]; int step; void init (int flag, int s) { step = s; for (int i = 1; i <= s; i++) { for (int j = 1; j <= s; j++) { if (i == j) e[i][j] = flag; else e[i][j] = 0; } } } void output_mat() { for (int i = 1; i <= step; i++) { for (int j = 1; j <= step; j++) { cout << e[i][j] << " "; } cout<<endl; } }} op;mat mul (mat a, mat b){ mat ret; ret.init (0, a.step); for (int i = 1; i <= ret.step; i++) { for (int j = 1; j <= ret.step; j++) { if (a.e[i][j]) { for (int k = 1; k <= ret.step; k++) { ret.e[i][k] += (a.e[i][j] * b.e[j][k]) % mod; ret.e[i][k] %= mod; } } } } return ret;}mat qpow (mat a,int p){ mat ret; ret.init (1, a.step); for (; p; p >>= 1) { if (p & 1) ret = mul(ret, a); a = mul(a, a); } return ret;}void init_op(){ op.init(0,7); op.e[1][1] = (k - 4) % mod; op.e[1][4] = (k - 3) % mod; op.e[1][5] = (k - 3) % mod; op.e[2][1] = 1; op.e[2][4] = 1; op.e[3][1] = 1; op.e[3][5] = 1; op.e[4][3] = (k - 3) % mod; op.e[4][7] = (k - 2) % mod; op.e[5][2] = (k - 3) % mod; op.e[5][6] = (k - 2) % mod; op.e[6][3] = 1; op.e[7][2] = 1;}ll fuct (ll x,int t){ ll ans = 1; for (int i = 0; i < t; i++) { ans *= (x - i) % mod; ans %= mod; } return ans;}ll meow(){ if (n <= 3) return fuct(k, n); if (k < 3) return 0; init_op(); op = qpow (op, n - 4); ll ans = 0; ans = (ans + op.e[1][1] * fuct (k, 4)) % mod; ans = (ans + op.e[1][3] * fuct (k, 3)) % mod; ans = (ans + op.e[5][1] * fuct (k, 4)) % mod; ans = (ans + op.e[5][3] * fuct (k, 3)) % mod; return ans;}int main(){ int n_case; scanf ("%d", &n_case); for (int i_case = 1; i_case <= n_case; i_case++) { scanf ("%d%d", &n, &k); printf ("Case %d: %lld\n", i_case, meow ()); } return 0;}
0 0
- 矩阵 uva 12037
- uva 11464 偶数矩阵
- UVA 矩阵链乘
- UVA - 10870(构造矩阵)
- Uva Recurrences 矩阵优化
- UVA 11464 偶数矩阵
- uva 10870 矩阵
- UVA 684 (矩阵行列式)
- 矩阵模板hdu5015,UVA 10655,UVA 11149
- UVA 442 - 矩阵链乘
- UVA 442 矩阵链乘
- uva 11149(矩阵倍增)
- UVA 10870 Recurrences 矩阵乘法
- uva 11992 快速矩阵操作
- uva-442-矩阵链乘
- uva 10870(矩阵快速幂)
- uva 12470(矩阵快速幂)
- UVa 11464 EvenParity 偶数矩阵
- VC6.0/MFC check box的获取对象的方法(部分)->针对初学者
- 获取特定的字符串
- Convert integer to string(int类型转化为string类型)
- 解析“extern”
- 动态规划 积木游戏
- 矩阵 uva 12037
- 51杂学
- 修改,编译sqoop
- 我的博客
- hdoj1048
- Hadoop-1.1.2、HBase-0.94.7完全分布式集群搭建
- 第二届acm省赛C identifier 字符串操作
- 2014年广州科目三道路驾驶技能考试/广汕路科目三路考系统操作和评判指南
- UML中的配置图、组件图