GTY’s birthday gift
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
FFZ’s birthday is coming. GTY wants to give a gift to ZZF. He asked his gay friends what he should give to ZZF. One of them said, ‘Nothing is more interesting than a number multiset.’ So GTY decided to make a multiset for ZZF. Multiset can contain elements with same values. Because GTY wants to finish the gift as soon as possible, he will use JURUO magic. It allows him to choose two numbers a and b(a,b∈S), and add a+b to the multiset. GTY can use the magic for k times, and he wants the sum of the multiset is maximum, because the larger the sum is, the happier FFZ will be. You need to help him calculate the maximum sum of the multiset.
Input
Multi test cases (about 3) . The first line contains two integers n and k (2≤n≤100000,1≤k≤1000000000). The second line contains n elements ai (1≤ai≤100000)separated by spaces , indicating the multiset S .
Output
For each case , print the maximum sum of the multiset (mod 10000007).
Sample Input
3 2
3 6 2
Sample Output
35
题意
按照规则扩展一个集合k次,然后求其总和。
分析
扩展规则很简单,就是一个斐波那契数列,但是如果按照模拟的方法手动推算,复杂度对于本题的数据范围来说是不太合适的。
可以利用矩阵快速幂来迅速完成。
$$\begin{bmatrix}S_{n-1}&F_n&F_{n-1}\end{bmatrix}*\begin{bmatrix}1&0&0\\1&1&1\\1&1&0\end{bmatrix}=\begin{bmatrix}S_n&F_{n+1}&F_n\end{bmatrix}$$
剩下要注意的就是数据范围要开到long long了,因为可能涉及到$10^9 * 10^9$这样的数量级。
1 | /* *********************************************** |