2019ACM-ICPC沈阳网络赛-K-Guanguan's Happy water(思维+暴力)

Guanguan‘s Happy water

4000ms

262144K

Rather than drinking happy water, Guanguan loves storing happy water. So he bought a refrigerator and stored a_iai? bottles of cola into it every day. When the storage is finished on the kk-th day, the refrigerator is full, but he still wants to store happy water every day. Here comes the solution: He first constructs a p-sequence: p_1p1?, p_2p2?, ..., p_kpk?, where p_1+p_2+...+p_k=1p1?+p2?+...+pk?=1. Then he chooses an number ii among 11 to kk, where number ii has the probability p_ipi? to be chosen. After that, he drinks the happy water stored on the ii-th day before the current day and stores the same amount of happy water back into the refrigerator again. Let the amount of happy water stored on the ii-th day be f_ifi?. Given the amount of happy water stored in the first kk days and the expected amount of the next kk days(which means, from the k+1k+1-th day to the 2k2k-th day), could you help Guanguan figure out the sum of the expected amount of happy water stored during the first nn days) (Be aware that every element of ff has moded 1e9+71e9+7 when input datas, and your output should mod 1e9+71e9+7 as well)

Input

The first line is TT (1 \le T \le 201≤T≤20), indicating the number of input sets. For each set of inputs, the first line is kk and nn (1 \le k \le 701≤k≤70, 1 \le n \le 10^{18}1≤n≤1018), and the second line is 2k2k numbers, respectively representing a_1a1?, a_2a2?, ..., a_kak?, f_{k+1}fk+1?, f_{k+2}fk+2?, ..., f_{2k}f2k?.

Output

For each data, output a non-negative integer indicating (\sum_{i=1}^n f_i) \mod 10^9+7(∑i=1n?fi?)mod109+7.

样例输入复制

2
1 9
2 2
2 8
6 5 5 5

样例输出复制

18
41

思路:

suma=(a1+a2+。。。+ak)

sumf=(f1+f2+。。。+f3)

①n<=k,ans=a1+a2+。。。+an;

②n<=2k,ans=suma+f1+f2+。。。+f(n-k);

③n>2k,ans=suma+((n-k)/k)*sumf+(   f1+f2+。。。+f( (n-k)%k )  ).

注意取模就行

AC代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int maxn=1e6+7;
 5 ll mod=1e9+7;
 6 ll a[maxn],f[maxn];
 7 int main()
 8 {
 9     int t;
10     scanf("%d",&t);
11     while(t--){
12         int k;
13         ll n,suma=0,sumf=0,k2;
14         scanf("%d",&k);
15         k2=ll(k);
16         scanf("%lld",&n);
17         for(int i=1;i<=k;++i)
18             scanf("%lld",&a[i]),suma=(suma+a[i])%mod;
19         for(int i=1;i<=k;++i)
20             scanf("%lld",&f[i]),sumf=(sumf+f[i])%mod;
21         ll ans=0;
22         if(k2>=n){
23             for(int i=1;i<=int(n);++i)
24                 ans=(ans+a[i])%mod;
25             printf("%lld\n",ans%mod);
26         }
27         else{
28             ans=suma%mod;
29             ll nu=((n-k2)/k2);
30             int len=n-nu*k2-k2;
31             nu%=mod;
32             ans=(nu*sumf+ans)%mod;
33             for(int i=1;i<=len;++i)
34                 ans=(ans+f[i])%mod;
35             printf("%lld\n",ans%mod);
36         }
37     }
38     return 0;
39 }
40 /*
41 2
42 2 100000000000000000
43 6 5 5 5
44 */

2019ACM-ICPC沈阳网络赛-K-Guanguan's Happy water(思维+暴力)

原文地址:https://www.cnblogs.com/CharlieWade/p/11519645.html

时间: 2024-07-29 19:15:03

2019ACM-ICPC沈阳网络赛-K-Guanguan's Happy water(思维+暴力)的相关文章

2015沈阳网络赛1003 Minimum Cut 树链剖分 数组维护前缀和进行区间增减

2015沈阳网络赛1003  Minimum Cut   树链剖分 数组维护前缀和进行区间增减 Minimum Cut Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Given a simple unweighted graph G 

2018 ICPC 徐州网络赛

2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution 将环变成链,设\(f[i][0\)~\(2]\),分别表示与第一个数相同,与第一个数不同,与第一个数相同,与第一个数的反相同.然后\(dp\)即可. 时间复杂度:\(O(n)\) B. BE, GE or NE solution 根据题目描述\(dp\)即可. 时间复杂度:\(O(nm)\) C.

2019 ICPC 南昌网络赛

2019 ICPC 南昌网络赛 比赛时间:2019.9.8 比赛链接:The 2019 Asia Nanchang First Round Online Programming Contest 总结 // 史上排名最高一次,开场不到两小时队友各A一题加水题共四题,排名瞬间升至三四十名 // 然后后三小时就自闭了,一题都没有突破...最后排名211 hhhh ? ? B. Fire-Fighting Hero 题意 队友做的,待补. ? AC代码 #include<cstdio> #includ

2019ACM-ICPC沈阳网络赛-C-Dawn-K&#39;s water(完全背包模板题)

Dawn-K's water  1000ms 262144K Dawn-K recently discovered a very magical phenomenon in the supermarket of Northeastern University: The large package is not necessarily more expensive than the small package. On this day, Dawn-K came to the supermarket

2015长春、沈阳网络赛总结

我所说的总结并不是谈什么题目解法之类的东西 这些东西网上有很多题解 说说这两场网赛吧! 这两场我的状态还行,只是xiaodong还没有找到状态,长春赛lucas+中国剩余定理他硬是打了一整场,还是没打出来,版题没打出来确实不该 wzb状态一般,不过看题的能力依然那么厉害 长春赛中,很遗憾的只出了5道题,按当时过题数目,应该是7道德,可是小东的lucas那题没打出来,而我打得后缀数组那题,当顺时针的时候不用看是否是下标最前面的,但是反过来就需要看了,当时想当然的认为不用,交了4发,一直wa到比赛结

沈阳网络赛G-Spare Tire【容斥】

17.64% 1000ms 131072K A sequence of integer \lbrace a_n \rbrace{an?} can be expressed as: \displaystyle a_n = \left\{ \begin{array}{lr} 0, & n=0\\ 2, & n=1\\ \frac{3a_{n-1}-a_{n-2}}{2}+n+1, & n>1 \end{array} \right.an?=????0,2,23an?1??an?2?

2016 年沈阳网络赛---QSC and Master(区间DP)

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legends, Northeastern University is the same. Enter from the north gate of Northeastern University,You are facing the main building of Northeastern Universi

2017 icpc 西安网络赛

F. Trig Function 样例输入 2 0 2 1 2 2 样例输出 998244352 0 2 找啊找啊找数列和论文.cosnx可以用切比雪夫多项式弄成(cosx)的多项式,然后去找到了相关的公式: 然后写个快速幂预处理啥的,很快就解决了~ 1 #include<bits/stdc++.h> 2 #define clr(x) memset(x,0,sizeof(x)) 3 #define clr_1(x) memset(x,-1,sizeof(x)) 4 #define LL lon

2016沈阳网络赛 Barricade

Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description The empire is under attack again. The general of empire is planning to defend his castle. The land can be seen as N towns and M roads, a