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 ...
随机推荐
- 【08】node 之 fs文件
var fs = require("fs");//fs 系统文件模块,对文件进行操作.Node.js 文件系统(fs 模块)模块中的方法均有异步和同步版本,例如读取文件内容的函数有 ...
- 面试:ios 批量上传图片
这几天面试,被问到关于GCD的用法,想了想,之前项目好像确实用的比较少,只是知道怎么用,有思路,但是却从来没有试过,回来之后,就尝试写了下: 封装图片上传的方法 /**批量上传图片*/ + (NSUR ...
- Windows通过data文件夹恢复mysql数据库
mysql--1146--报错 先找到数据库存放地址,即Data文件夹(复制留下来) 再用电脑管家把所有的mysql卸载 然后把mysql文件夹弄走(卸载不会清掉它,需手动,一般在C:\Program ...
- URAL1960 Palindromes and Super Abilities
After solving seven problems on Timus Online Judge with a word “palindrome” in the problem name, Mis ...
- 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---17
以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:
- 浏览器中“JavaScript解析器”工作原理
浏览器在读取HTML文件的时候,只有当遇到<script>标签的时候,才会唤醒所谓的“JavaScript解析器”开始工作. JavaScript解析器工作步骤: 1.“找一些东西”: v ...
- hdu 4522(图论,构图)
湫湫系列故事——过年回家 Time Limit: 500/200 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total ...
- IIS 配置缓存
IIS8设置应用程序池-高级设置-启动模式:AlwaysRunning 应用程序池-高级设置-进程模型-闲置超时:1740 (分钟) 应用程序-高级设置-常规-预加载已启用:True
- VS恢复默认设置
通过“导入和导出设置”实现VS恢复默认设置 1.快捷步骤 工具 → 导入和导出设置 → 重置所有设置 → 下一步 → 选择“是否保存当前设置”,下一步 → 选择“要重置的开发语言(如,Visual C ...
- AndroidStudio不重新运行,Debug调试已有进程
们在使用AndroidStudio进行编写Android应用程序的时候,经常需要对抛出的问题进行断点调试跟踪,如果不知道怎样直接调试已经运行的进程.那么调试的效率会非常低下!下面我就来教大家如何快速调 ...