题意非常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 数论+组合数学的更多相关文章

  1. CodeForces 223C Partial Sums 多次前缀和

    Partial Sums 题解: 一个数列多次前缀和之后, 对于第i个数来说他的答案就是 ; i <= n; ++i){ ; j <= i; ++j){ b[i] = (b[i] + 1l ...

  2. 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 ...

  3. 51nod1161 Partial Sums

    开始想的是O(n2logk)的算法但是显然会tle.看了解题报告然后就打表找起规律来.嘛是组合数嘛.时间复杂度是O(nlogn+n2)的 #include<cstdio> #include ...

  4. 51 Nod 1161 Partial sums

    1161 Partial Sums  题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  取消关注 给出一个数组A,经过一次 ...

  5. [codeforces 509]C. Sums of Digits

    [codeforces 509]C. Sums of Digits 试题描述 Vasya had a strictly increasing sequence of positive integers ...

  6. Non-negative Partial Sums(单调队列)

    Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  7. hdu 4193 Non-negative Partial Sums 单调队列。

    Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  8. TOJ 1721 Partial Sums

    Description Given a series of n numbers a1, a2, ..., an, the partial sum of the numbers is defined a ...

  9. 【计数】cf223C. Partial Sums

    考试时候遇到这种题只会找规律 You've got an array a, consisting of n integers. The array elements are indexed from ...

随机推荐

  1. JavaScript 笔记(7) -- 在HTML中嵌入 js (外部引用)

    本节主要说明,在HTML中嵌入自定义 JavaScript.通过HTML的script标签加载JavaScript文件 为防止网页加载缓慢,也可以把非关键的JavaScript放到网页底部,例如下面的 ...

  2. 石子游戏Kam(bzoj 1115)

    Description 有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要保证操作后仍然满足初始时的条件谁没有石子可移时输掉游戏 ...

  3. POJ3983 快算24

    很正常的题目,迷一样的答案. 测试数据只有一组,对没错只有一组. #include<cstdio> int main() { printf("5*(5-(1/5))\n" ...

  4. EF4.2预览版出来了

    原文发布时间为:2011-09-21 -- 来源于本人的百度文章 [由搬家工具导入] http://blogs.msdn.com/b/adonet/archive/2011/08/22/ef-4-2- ...

  5. Python连接MySQL数据库操作

    一.创建数据库及表 CREATE DATABASE testdb; USE testdb; CREATE TABLE `tb_user` ( `id` INT (11) NOT NULL AUTO_I ...

  6. android中与Adapter相关的控件----ViewFlipper

    ViewFlipper(翻转视图) 一.ViewFlipper是一个多页面管理的控件,与ViewPager不同,ViewPager的是一页一页的的,而ViewFlipper则是一层一层的.图片轮播或者 ...

  7. C#使用DirectoryEntry类操作Windows帐户

    1.创建windows帐户 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /// <summary> /// 创建Windows帐户 /// </summa ...

  8. PHP二维数组排序研究

    前几天在项目中碰到了一个问题,在做商城的时候,要对一个店铺里所有商品进行价格排序,而且每一种商品都拥有多个规格,要取到所有商品中所有规格的最低价和最高价,发现PHP有很友好的函数帮助我们进行筛选. 使 ...

  9. 自做CA自签发SSL证书

    一.把证书准备好.步骤与使用OpenSSL自签发服务器https证书所述大同小异.在这里再重复一次.1.制作CA证书:ca.key CA私钥: openssl genrsa -des3 -out ca ...

  10. [HAOI2011]Problem b&&[POI2007]Zap

    题目大意: $q(q\leq50000)$组询问,对于给定的$a,b,c,d(a,b,c,d\leq50000)$,求$\displaystyle\sum_{i=a}^b\sum_{j=c}^d[\g ...