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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Hdoj 1757

發布時間:2025/3/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Hdoj 1757 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

描述

Lele now is thinking about a simple function f(x).
If x < 10 f(x) = x.
If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10);
And ai(0<=i<=9) can only be 0 or 1 .
Now, I will give a0 ~ a9 and two positive integers k and m ,and could you help Lele to caculate f(k)%m.

輸入

The problem contains mutiple test cases.Please process to the end of file.
In each case, there will be two lines.
In the first line , there are two positive integers k and m. ( k<2*10^9 , m < 10^5 )
In the second line , there are ten integers represent a0 ~ a9.

輸出

For each case, output f(k) % m in one line.

樣例輸入

10 9999
1 1 1 1 1 1 1 1 1 1
20 500
1 0 1 0 1 0 1 0 1 0

樣例輸出

45
104

思路

很基礎的矩陣快速冪

代碼

#include <cstdio> #include<cstring> #define ll long long #define maxn 10 using namespace std;int k, mod;struct Mat {ll f[maxn][maxn];void cls(){memset(f, 0, sizeof(f));}//全部置為0 Mat() {cls();}friend Mat operator * (Mat a, Mat b){Mat res;for(int i = 0; i < maxn; i++) for(int j = 0; j < maxn; j++)for(int k = 0; k < maxn; k++)(res.f[i][j] += a.f[i][k] * b.f[k][j]) %= mod;return res;} };Mat quick_pow(Mat a) { Mat ans;for(int i = 0; i < maxn; i++) ans.f[i][i] = 1;int b = k;while(b != 0) {if(b & 1) ans = ans * a;b >>= 1;a = a * a;}return ans; }int main() {Mat A, B;for(int i = 0; i < 10; i++)B.f[0][i] = 9 - i;for(int i = 1; i < 10; i++) A.f[i-1][i] = 1;while(~scanf("%d %d", &k, &mod)){Mat C;for(int i = 0; i < 10; i++) scanf("%d", &A.f[i][0]);if(k < 10) {printf("%d\n", k % mod); continue;}k -= 9;C = quick_pow(A);C = B * C;printf("%d\n", C.f[0][0]);}return 0; }

轉載于:https://www.cnblogs.com/HackHarry/p/8392106.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。