51nod1161 Partial Sums
开始想的是O(n2logk)的算法但是显然会tle。看了解题报告然后就打表找起规律来。嘛是组合数嘛。时间复杂度是O(nlogn+n2)的
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
#define ll long long
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int nmax=5e3+5;
const int mod=1e9+7;
ll ans[nmax],a[nmax];
ll pow(ll x,int n){
ll res=x;--n;
while(n){
if(n&1) res=res*x%mod;
x=x*x%mod;n>>=1;
}
return res;
}
int main(){
int n=read(),m=read();--m;
ans[1]=1;
rep(i,2,n) ans[i]=ans[i-1]*(i+m-1)%mod*pow(i-1,mod-2)%mod;
ll tp,u;
rep(i,1,n) a[i]=read();
rep(i,1,n){
tp=0;
rep(j,1,i) tp=(tp+ans[j]*a[i-j+1])%mod;
printf("%lld\n",tp);
}
return 0;
}
第1行,2个数N和K,中间用空格分隔,N表示数组的长度,K表示处理的次数(2 <= n <= 5000, 0 <= k <= 10^9, 0 <= a[i] <= 10^9)
共N行,每行一个数,对应经过K次处理后的结果。每次累加后mod 10^9 + 7。
4 2
1
3
5
6
1
5
14
29
51nod1161 Partial Sums的更多相关文章
- 题解 [51nod1161] Partial Sums
题面 解析 我们设\(f[i]\)表示\(k\)次操作后第一个数在第\(i\)个位置上加了多少次, 而其它的数也可以类推, 第\(i\)个数在第\(j\)个位置加的次数就是\(f[j-i+1]\). ...
- 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 ...
- CodeForces 223C Partial Sums 多次前缀和
Partial Sums 题解: 一个数列多次前缀和之后, 对于第i个数来说他的答案就是 ; i <= n; ++i){ ; j <= i; ++j){ b[i] = (b[i] + 1l ...
- 51 Nod 1161 Partial sums
1161 Partial Sums 题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 取消关注 给出一个数组A,经过一次 ...
- 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 ...
- hdu 4193 - Non-negative Partial Sums(滚动数列)
题意: 给定一个由n个整数组成的整数序列,可以滚动,滚动的意思就是前面k个数放到序列末尾去.问有几种滚动方法使得前面任意个数的和>=0. 思路: 先根据原来的数列求sum数组,找到最低点,然后再 ...
随机推荐
- 安装hbase-0.98.9-hadoop2
1. download http://124.202.164.13/files/1244000005C563FC/www.eu.apache.org/dist/hbase/stable/hbase-0 ...
- ASP.NET和JSP相似方法总结(持续中。。)
一.HTTP请求处理 1.获取GET请求数据 ASP.NET:Request.QueryString[name] JSP:request.getParameter(String name); 2.解决 ...
- GCD使用小结
- ( * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSLog(; i < ; i ++) { [self o ...
- React.js 样式组件:React Style
点这里 React Style 是 React.js 可维护的样式组件.使用 React Native StyleSheet.create一样的样式. 完全使用 JavaScript 定义样式: ? ...
- windows JDK 版本切换
windows JDK 版本切换1. HKEY_LOCAL_MACHINE“SOFTWARE“JavaSoft“Java Runtime Environment“CurrentVersion, 把这个 ...
- ExtJs之VTYPE验证
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- MongoDB (三) MongoDB 安装
MongoDB安装在Windows上 在 Windows上,首先要安装 MongoDB下载最新发布的MongoDB: http://www.mongodb.org/downloads 确保得到正确的版 ...
- linux 下Time_wait过多问题解决
linux 下Time_wait过多问题解决 net.ipv4.tcp_syncookies = 1表示开启SYN Cookies.当出现SYN等待队列溢出时,启用cookies来处理,可防范少量SY ...
- grep是模糊匹配
1. 我:我用的ps -nat|grep -i "80"|wc -l命令 我:解释详细点,,龙哥,对于我这种菜鸟:也是模糊匹配 :你用 grep "80" 会匹 ...
- Linux基础--用户和组管理
1.账号管理相关文件 1)/etc/passwd 每一行都代表一个账号,有几行就代表有几个账号在你的系统中,不过需要特别留意的是,里头很多账号本来就是系统中必须要的,我们可以简称他为系统账号, ...