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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

[HDU517] 小奇的集合

發布時間:2023/12/9 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [HDU517] 小奇的集合 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目鏈接

顯然有貪心每次選擇最大的兩個數來做。

于是暴力地把最大的兩個數調整到非負(暴力次數不超過1e5),接下來使用矩陣乘法即可。

\[ \begin{pmatrix} B'\\S'\\T' \end{pmatrix} = \begin{pmatrix} 1&1&0\\ 1&0&0\\ 1&1&1 \end{pmatrix} \begin{pmatrix} B\\S\\T \end{pmatrix} \]

#include <bits/stdc++.h> using namespace std; const int mod=1e7+7;struct Node {int a[3][3];int *operator[](const int&d) {return a[d];}const int *operator[](const int&d) const{return a[d];}Node operator*(const Node&b) const{Node c; memset(&c,0,sizeof c);for(int i=0; i<3; ++i) for(int k=0; k<3; ++k) if(a[i][k])for(int j=0; j<3; ++j)c[i][j]=(c[i][j]+1LL*a[i][k]*b[k][j]%mod)%mod;return c;}Node pow(int y) {Node c,x=*this;for(int i=0; i<3; ++i) for(int j=0; j<3; ++j) c[i][j]=(i==j);for(; y; y>>=1,x=x*x) if(y&1) c=c*x;return c;} } G,M;int n,k,sum,a[200010];int main() {scanf("%d%d",&n,&k);for(int i=1; i<=n; ++i) {scanf("%d",a+i);sum=(sum+a[i]+mod)%mod;}sort(a+1,a+n+1);while(a[n-1]<0&&k>0) {a[n+1]=(a[n]+a[n-1]); n++; k--;sum=(sum+a[n]+mod)%mod;swap(a[n],a[n-1]);}if(k==0) {printf("%d\n",sum);return 0;}M[0][0]=a[n];M[1][0]=a[n-1];M[2][0]=sum;G[0][0]=G[0][1]=1;G[1][0]=1;G[2][0]=G[2][1]=G[2][2]=1;Node ans=G.pow(k)*M;printf("%d\n",ans[2][0]);return 0; }

轉載于:https://www.cnblogs.com/nosta/p/11042648.html

總結

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

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