Codeforces 223C Partial Sums 数论+组合数学
题意非常easy,求不是那么好求的,k非常大 要操作非常多次,所以不可能直接来的。印象中解决操作比較多无非线段树 循环节 矩阵 组合数等等吧,这道题目 也就仅仅能多画画什么 的了
就以第一个案例为主吧 。
3
1 2 3
k我们根据画的次数来自己定好了
以下的每一个数表示这个位置的 数由最初的 数组num[]中多少个数加起来得到的
当k为0的时候呢。就是
1 1 1
k为1的时候呢
1 2 3
k为2的时候呢
1 3 6
那么k为3的时候
1 4 10
这里看一下 从数组下标0開始。那么事实上就是 C(i + k,i)
认为不够的话呢 能够再多写几个,发现就是这么回事啊 。跟组合数有联系了,那么肯定不可能每一次都求啊 ,所以能够试着搞一个矩阵,这样就能够做了
做的时候组合数直接来超时了,能够先用一个c数组预处理出全部的组合数答案,求答案运用C(n,m) == C(n,n - m)这样省时间这样也是700+ms比較慢,当然若是再把乘法逆元给 先预处理存到数组里会更加省时间 并且会省非常多。
#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<memory.h>
#include<set> #define ll long long #define eps 1e-8 const int inf = 0xfffffff; const ll INF = 1ll<<61; using namespace std; //vector<pair<int,int> > G;
//typedef pair<int,int > P;
//vector<pair<int,int> > ::iterator iter;
//
//map<ll,int >mp;
//map<ll,int >::iterator p; #define MOD 1000000007 ll num[2000 + 5]; int n,k; ll exgcd(ll a, ll b, ll &x, ll &y) {
if(!b) {
x = 1; y = 0;
return a;
}
ll r = exgcd(b, a%b, y, x);
y -= a/b*x;
return r;
} ll inv(ll a, ll m)
{
ll x,y,gcd = exgcd(a, m, x, y);
if(x < 0)
x += m;
return x;
} ll C(ll n,ll m) {
ll ans = 1;
for(int i=1;i<=m;i++)
ans = ((ans * inv(i,MOD))%MOD * (n - i + 1))%MOD;
return ans;
} ll c[2000 + 5]; int main() {
while(scanf("%d %d",&n,&k) == 2) {
for(int i=0;i<n;i++)
scanf("%d",&num[i]);
if(k == 0) {
for(int i=0;i<n;i++)
printf("%I64d%c",num[i],i == n - 1? '\n':' ');
continue;
}
for(int i=0;i<n;i++)
c[i] = C(i + k - 1,i);
for(int i=0;i<n;i++) {
ll ans = 0ll;
for(int j=0;j<=i;j++) {
//ll tmp = C(i - j + k - 1,i - j);
//ll tt = num[j];
ans = (ans + num[j] * c[i - j])%MOD;
}
printf("%I64d%c",ans,i == n - 1? '\n':' ');
}
}
return 0;
}
Codeforces 223C Partial Sums 数论+组合数学的更多相关文章
- CodeForces 223C Partial Sums 多次前缀和
Partial Sums 题解: 一个数列多次前缀和之后, 对于第i个数来说他的答案就是 ; i <= n; ++i){ ; j <= i; ++j){ b[i] = (b[i] + 1l ...
- 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 ...
- 51nod1161 Partial Sums
开始想的是O(n2logk)的算法但是显然会tle.看了解题报告然后就打表找起规律来.嘛是组合数嘛.时间复杂度是O(nlogn+n2)的 #include<cstdio> #include ...
- 51 Nod 1161 Partial sums
1161 Partial Sums 题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 取消关注 给出一个数组A,经过一次 ...
- [codeforces 509]C. Sums of Digits
[codeforces 509]C. Sums of Digits 试题描述 Vasya had a strictly increasing sequence of positive integers ...
- 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 ...
- 【计数】cf223C. Partial Sums
考试时候遇到这种题只会找规律 You've got an array a, consisting of n integers. The array elements are indexed from ...
随机推荐
- react-router路由参数
react-router会自动为路由组件插入三个参数,但是不会主动为路由组件的子组件注入 子组件当中需要在属性当中传入 不是路由组件需要注入路由参数的话,也可以使用withRouter注入,而不是从属 ...
- L#中 int.TryParse 有问题
今天发现了一个 L# 的异常..因此记录一下 List<string> strList = new List<string>(); ; i<; ++i) { ; j< ...
- Codeforces Round #398 (Div. 2) A-E
分数史上新低 开场5分钟过了A题,想着这次赌一把手速,先去切C吧 看完C题觉得这应该是道水题,码了十分钟提交,WA 想着这明明是道水题,估计少考虑了情况,添了几行再交,WA 不可能啊,这题都A不掉,和 ...
- URAL1960 Palindromes and Super Abilities
After solving seven problems on Timus Online Judge with a word “palindrome” in the problem name, Mis ...
- Repeater的使用及其鼠标特效,行链接的使用
原文发布时间为:2009-04-22 -- 来源于本人的百度文章 [由搬家工具导入] <asp:Repeater ID="rpt" runat="server&qu ...
- 【程序打包工具 Inno Setup】转
原文转自 https://jingyan.baidu.com/article/36d6ed1f50ecfc1bcf4883aa.html
- BusyBox 简化嵌入式 Linux 系统【转】
转自:http://www.cnblogs.com/hnrainll/archive/2011/06/10/2077393.html BusyBox 的诞生 BusyBox 最初是由 Bruce Pe ...
- Hrbust 2320 OX (博弈)
题目链接 Hrbust 2320 用三进制来存储整个棋盘的状态. 设$dp[status][now]$为轮到$now$下棋的时候是必胜必败还是平局. 那么若当前能延伸出的所有状态中存在必败态的,则当 ...
- httpd安装和配置(cgi、wsgi)
参考:http://webpy.org/cookbook/mod_wsgi-apache.zh-cn 一.yum方式安装: 1.yum install httpd 输入y后继续. 2.看到一下类似的返 ...
- 洛谷——P3387 【模板】缩点
P3387 [模板]缩点 题目背景 缩点+DP 题目描述 给定一个n个点m条边有向图,每个点有一个权值,求一条路径,使路径经过的点权值之和最大.你只需要求出这个权值和. 允许多次经过一条边或者一个点, ...