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 ...
随机推荐
- BZOJ 4500: 矩阵
4500: 矩阵 Time Limit: 1 Sec Memory Limit: 256 MBSubmit: 326 Solved: 182[Submit][Status][Discuss] De ...
- java网络编程学习笔记(三):ServerSocket详解
1.ServerSocket的构造方法 ServerSocket(); ServerSocket(int port); ServerSocket(int port,int backlog); Serv ...
- SQL Server 2005 无法连接到 127.0.0.1
[问题描述]如果连接本机的数据库服务器,服务器名称可填: 127.0.0.1或localhost或本机机器全名(比如HOME),有时候用本机机器名可以登录SQL Server 2005,但用127.0 ...
- Swift Perfect 服务器配置(Ubuntu16.0.4 主机、虚拟机)
Mac 开发环境 brew install mysql@5.7 && brew link mysql@5.7 --force mysql.server startmysql_secur ...
- getchar吸收回车
#include "stdio.h" int main() { int a; char b,c; scanf("%d",&a); c = getchar ...
- FZU 1075 分解素因子【数论/唯一分解定理/分解素因子裸模板】
[唯一分解定理]:https://www.cnblogs.com/mjtcn/p/6743624.html 假设x是一个正整数,它的值不超过65535(即1<x<=65535),请编写一个 ...
- Hrbust 2320 OX (博弈)
题目链接 Hrbust 2320 用三进制来存储整个棋盘的状态. 设$dp[status][now]$为轮到$now$下棋的时候是必胜必败还是平局. 那么若当前能延伸出的所有状态中存在必败态的,则当 ...
- Unix进程和线程管理及其异同
Unix进程和线程管理及其异同 一,进程 1,什么是进程 在最初的单处理器系统中,系统中的多道程序按照一定规则切换而实现多任务处理,后来发现多个程序并发导致系统资源被共享,为了描述和管理程序对共享资源 ...
- Jenkins连接git时出现“Failed to connect to repository : Command ... HEAD" returned status code 128:”的问题解决
网上说的解决方法如下: 其实生成ssh时不应该使用当前用户去生成ssh,而是使用jenkins这个用户去生成ssh,然后再去git服务器上配置你生成key,最后再jenkins上配置返回给你的key. ...
- 【spring boot】8.spring boot的日志框架logback使用
在继续上一篇的Debug调试之后,把spring boot的日志框架使用情况逐步蚕食. 参考:http://tengj.top/2017/04/05/springbo 开篇之前,贴上完整applica ...