【计数】cf223C. Partial Sums
考试时候遇到这种题只会找规律
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that:
- First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals
. The operation x mod y means that we take the remainder of the division of number x by number y.
- Then we write the contents of the array s to the array a. Element number i (1 ≤ i ≤ n) of the array s becomes the i-th element of the array a (ai = si).
You task is to find array a after exactly k described operations are applied.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109).
Output
Print n integers — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces.
题目分析
可以从矩阵乘法开始想起,考虑转移矩阵,发现其主对角线下方全为0、元素按照次对角线对称。
或者就是找规律
3.16upd:
总觉得一个经典模型不应该用找规律这么假的方式随随便便搞掉吧……
网上的题解都是打表找规律 | 矩乘找规律 | dp找规律……
来自ZZK的新的理解方式:$a_i$的贡献也就是它走到$s^p_j$的方案数量。
- #include<bits/stdc++.h>
- #define MO 1000000007
- const int maxn = ;
- int n,k,a[maxn],b[maxn],inv[maxn],fac[maxn],pre[maxn];
- void init()
- {
- fac[] = fac[] = inv[] = inv[] = ;
- for (int i=; i<=n; i++)
- fac[i] = 1ll*fac[i-]*i%MO,
- inv[i] = MO-1ll*(MO/i)*inv[MO%i]%MO;
- pre[] = ;
- for (int i=; i<=n; i++)
- pre[i] = 1ll*pre[i-]*(k%MO+i-)%MO*inv[i]%MO;
- }
- int main()
- {
- scanf("%d%d",&n,&k);
- for (int i=; i<=n; i++) scanf("%d",&a[i]), b[i] = a[i];
- if (k){
- init();
- for (int i=; i<=n; i++)
- {
- b[i] = ;
- for (int j=; j<=i; j++)
- b[i] = 1ll*(b[i]+1ll*pre[i-j]*a[j]%MO)%MO;
- }
- }
- for (int i=; i<=n; i++) printf("%d ",b[i]);
- return ;
- }
END
【计数】cf223C. Partial Sums的更多相关文章
- 51nod1161 Partial Sums
开始想的是O(n2logk)的算法但是显然会tle.看了解题报告然后就打表找起规律来.嘛是组合数嘛.时间复杂度是O(nlogn+n2)的 #include<cstdio> #include ...
- Non-negative Partial Sums(单调队列)
Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- hdu 4193 Non-negative Partial Sums 单调队列。
Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- TOJ 1721 Partial Sums
Description Given a series of n numbers a1, a2, ..., an, the partial sum of the numbers is defined a ...
- CodeForces 223C Partial Sums 多次前缀和
Partial Sums 题解: 一个数列多次前缀和之后, 对于第i个数来说他的答案就是 ; i <= n; ++i){ ; j <= i; ++j){ b[i] = (b[i] + 1l ...
- 51 Nod 1161 Partial sums
1161 Partial Sums 题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 取消关注 给出一个数组A,经过一次 ...
- CF思维联系–CodeForces - 223 C Partial Sums(组合数学的先线性递推)
ACM思维题训练集合 You've got an array a, consisting of n integers. The array elements are indexed from 1 to ...
- CF223C【Partial Sums】(组合数学+乱搞)
题面 传送门 题解 orz zzk 考虑这东西的组合意义 (图片来自zzk) \(a_i\)这个元素对\(k\)阶前缀和的第\(j\)个元素\(s_{k,j}\)的贡献就等于从\((0,i)\)走到\ ...
- hdu 4193 - Non-negative Partial Sums(滚动数列)
题意: 给定一个由n个整数组成的整数序列,可以滚动,滚动的意思就是前面k个数放到序列末尾去.问有几种滚动方法使得前面任意个数的和>=0. 思路: 先根据原来的数列求sum数组,找到最低点,然后再 ...
随机推荐
- leetcode 91. 解码方法
题目描述: 一条包含字母 A-Z 的消息通过以下方式进行了编码: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 给定一个只包含数字的非空字符串,请计算解码方法的总数 ...
- UnityError AnimationEvent 'NewEvent' has no receiver! Are you missing a component?
- 深入理解C#中的IDisposable接口(转)
转自:https://www.cnblogs.com/wyt007/p/9304564.html 写在前面 在开始之前,我们需要明确什么是C#(或者说.NET)中的资源,打码的时候我们经常说释放资源, ...
- css相关知识
display: block; "块级元素". display: inline; "行内元素". display: none; "在不删除元素的情况下 ...
- 消除transition闪屏
消除transition闪屏.css {-webkit-transform-style: preserve-3d;-webkit-backface-visibility: hidden;-webkit ...
- Java调用webservice接口方法(SOAP message、xfire、axis)
webservice的 发布一般都是使用WSDL(web service descriptive language)文件的样式来发布的,在WSDL文件里面,包含这个webservice暴露在外面可供使 ...
- Struts2初级篇(HelloWorld)
Struts2的工作流程: 从一个高水平角度看,Struts2 是一个MVC拉动的(或MVC2)框架,Struts2 的模型-视图-控制器模式是通过以下五个核心部分进行实现的: 操作(Actions) ...
- agc007B - Construct Sequences(构造)
题意 题目链接 给出一个$1-N$的排列$P$,构造两个数组$a, b$满足 Sol 发现我的水平也就是能做一做0-699的题.... 直接构造两个等差数列$a, b$,公差为$20000$ 然后从小 ...
- vue封装storage案例
src/model/storage.js var storage={ set(key,value){ localStorage.setItem(key,JSON.stringify(value)); ...
- java 千分位的添加和去除
转至:http://blog.sina.com.cn/s/blog_8f99a1640102v1xh.html 将一个数字转换为有千分位的格式: NumberFormat numberFormat1 ...