日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Count

發(fā)布時間:2024/10/5 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Count 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=843

題解:矩陣快速冪

參考文章:https://blog.csdn.net/weixin_43272781/article/details/85939539

/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int using namespace std; typedef long long ll; //typedef __int128 lll; const int N=6; const int M=100000+10; const int MOD=123456789; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; ll t,n,m,k,q; ll ans,cnt,flag,temp,sum; char str; struct node{}; ll tmp[N][N]; void multi(ll a[][N],ll b[][N],int n) {memset(tmp,0,sizeof (tmp));for(int i=0;i<n;i++)for(int j=0;j<n;j++)for(int k=0;k<n;k++)tmp[i][j]=(tmp[i][j]+a[i][k]*b[k][j])%MOD;for(int i=0;i<n;i++)for(int j=0;j<n;j++)a[i][j]=tmp[i][j]; } ll res[N][N]; void Pow(ll a[][N],ll b) {memset(res,0,sizeof res);//n是冪,N是矩陣大小for(int i=0;i<N;i++)res[i][i]=1;while(b){if(b&1)multi(res,a,N);//res=res*a;復(fù)制直接在multi里面實(shí)現(xiàn)了;multi(a,a,N);//a=a*ab>>=1;}for(int i=0;i<N;i++)for(int j=0;j<N;j++)a[i][j]=res[i][j]; }int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);scanf("%lld",&t);while(t--){scanf("%lld",&n);ll a[N][N]={{1,2,1,3,3,1},//f[n]{1,0,0,0,0,0},//f[n-1]{0,0,1,3,3,1},//n3{0,0,0,1,2,1},//n2{0,0,0,0,1,1},//n1{0,0,0,0,0,1}};//n0ll b[N][N]={{2,0,0,0,0,0},{1,0,0,0,0,0},{8,0,0,0,0,0},{4,0,0,0,0,0},{2,0,0,0,0,0},{1,0,0,0,0,0}};Pow(a,n-2); // for(int i=0;i<6;i++){ // for(int j=0;j<6;j++){ // printf("%lld%c",a[i][j]," \n"[j==5]); // } // }multi(a,b,N);cout<<a[0][0]<<endl; // for(int i=0;i<6;i++){ // for(int j=0;j<6;j++){ // printf("%lld%c",a[i][j]," \n"[j==5]); // } // }}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC); #endif//cout << "Hello world!" << endl;return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的Count的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。