HDU
来源:互联网 发布:便宜域名注册 编辑:程序博客网 时间:2024/06/04 18:59
题目大意:
给你一个递推式:
分析:
求一个转移矩阵就好了,然后矩阵快速幂手打了一次。
代码:
#include<bits/stdc++.h>using namespace std;#define mod 2147493647struct point{ long long int a[8][8];};long long int xcx[8][8]={ {0,0,0,0,0,0,0,0}, {0,1,2,1,0,0,0,0}, {0,1,0,0,0,0,0,0}, {0,0,0,1,4,6,4,1}, {0,0,0,0,1,3,3,1}, {0,0,0,0,0,1,2,1}, {0,0,0,0,0,0,1,1}, {0,0,0,0,0,0,0,1}};long long int ans=0;long long int star[8]={0,0,0,81,27,9,3,1};point get_mul(point a,point b){ point ans; for(int i=1;i<8;i++) { for(int j=1;j<8;j++) { ans.a[i][j]=0; for(int k=1;k<8;k++) { ans.a[i][j]+=(a.a[i][k]*b.a[k][j]); ans.a[i][j]%=mod; } } } return ans;}void out_put(point x){ for(int i=1;i<8;i++) { for(int j=1;j<8;j++) { printf("%d ",x.a[i][j]); } printf("\n"); }}int main(){ int t; long long int n; scanf("%d",&t); while(t--) { ans=0; scanf("%lld%lld%lld",&n,&star[2],&star[1]); point e; point now; for(int i=0;i<8;i++) { for(int j=0;j<8;j++) { if(i==j)e.a[i][j]=1; else e.a[i][j]=0; now.a[i][j]=xcx[i][j]; } } n-=2; while(n>0) { if(n%2==1) { e=get_mul(e,now); } now=get_mul(now,now); n/=2; } for(int i=1;i<8;i++) { ans+=(e.a[1][i]*star[i]); ans%=mod; } //out_put(e); printf("%lld\n",ans); }}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 机器学习产品经理工作流程
- 获取手机中sdCard的权限
- Matlab GUI,显示学生成绩(读取txt,xls文件),打开文件对话框
- DNA Consensus String UVA
- 实验四
- HDU
- 如何在 Ubuntu 上用 Yocto 创建你自己的嵌入式 Linux 发行版
- 多选框
- 3011: [Usaco2012 Dec]Running Away From the Barn
- 将二叉树拆成链表-LintCode
- Periodic Strings UVA
- 信息学奥赛一本通(C++版) 第一部分 C++语言 第一章 C++语言入门
- java面试题之集合框架
- Cg Programming/Unity/Two-Sided Smooth Surfaces双面平滑曲面