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 ...
随机推荐
- artTemplate模板引擎的不同使用方式
arttemplate提供了两种不同的使用方式 一种是将模板写在页面内 <script id="test" type="text/html"> &l ...
- C#中的继承与覆盖
原文发布时间为:2009-03-03 -- 来源于本人的百度文章 [由搬家工具导入] //using System;//using System.Collections.Generic;using S ...
- socket介绍(webService适用场景)
1.使用场景 - 不同的移动客户端访问 - 需要访问第三方的项目 2.访问第三方应用的方式 ISO的七层模型 : 物理层.数据链路层.网络层.传输层.表示层.会话 ...
- Android解析XML之SAX解析器
SAX(Simple API for XML)解析器是一种基于事件的解析器,它的核心是事件处理模式,主要是围绕着事件源以及事件处理器来工作的.当事件源产生事件后,调用事件处理器相应的处理方法,一个事件 ...
- 设置div自适应高度滚动
<body> <div id="divc" style="overflow: auto;"> </div> <a id ...
- selenium入门教程c#
一. 简述 1. 介绍 Selenium是ThoughtWorks专门为Web应用程序编写的一个验收测试工具. Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE. ...
- python名词解释(生成器,匿名函数)
1.生成器:能够保持状态的迭代器,下次进去还是之前出来的状态 http://www.oschina.net/translate/improve-your-python-yield-and-genera ...
- Gym 101064 D Black Hills golden jewels 【二分套二分/给定一个序列,从序列中任意取两个数形成一个和,两个数不可相同,要求求出第k小的组合】
D. Black Hills golden jewels time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Topcoder SRM 666 DIV 1
WalkOverATree 题意:给你一棵树,有个人在节点0,现在问你,这个人走L步,最多能访问多少个不同的节点,一个节点可以被走多次,但只算一次. 题解:这个问题的关键在于,每个点最多走两次,这是因 ...
- Word Break - LeetCode
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...