二项式定理+前缀Sigma
https://hihocoder.com/problemset/problem/1430
思路:
要用前缀去推Sigma总公式,比较方便。https://blog.csdn.net/weixin_37517391/article/details/83821752
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//and(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
const double E=2.718281828;
const double PI=acos(-1.0);
//const ll INF=(1LL<<60);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)5e4+; long long C[][];
void Init() {
C[][] = ;
for(int i = ;i <= ;++i) {
C[i][] = ;
for(int j = ;j <= i;++j) {
C[i][j] = (C[i-][j-] + C[i-][j]) % mod;
}
}
}
//======================================================Cnk预处理;
ll S[][N],SS[][N],ans[N];
char s[N]; void solve()
{
ll n,k;
sc("%lld%lld",&n,&k);
sc("%s",s); for(int i = ;i <= n;++i) S[][i] = ;
for(int i = ;i <= n;++i) S[][i] = (s[i-]-'') + S[][i-] ;
for(int i = ;i <= k;++i)
for(int j = ;j <= n;++j)
S[i][j] = S[][j] * S[i-][j] % mod; SS[][] = ; for(int i = ;i <= k;++i) {
for(int j = ;j <= n;++j)
SS[i][j] = (SS[i][j-] + S[i][j])%mod;
} for(int i=;i<=n;++i)
{
ll sum=;
for(int j=;j<=k;++j)
{
ll temp=C[k][j]*S[k-j][i]%mod*SS[j][i-]%mod;
if(j&)
sum=(sum-temp+mod)%mod;
else
sum=(sum+temp)%mod;
}
ans[i]=sum;
}
for(int i=;i<=n;++i)
pr("%lld%c",ans[i],i==n?'\n':' ');
} int main()
{
Init();
int T;
sc("%d",&T);
while(T--)solve();
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}
二项式定理+前缀Sigma的更多相关文章
- A Boring Problem UVALive - 7676 (二项式定理+前缀和)
题目链接: I - A Boring Problem UVALive - 7676 题目大意:就是求给定的式子. 学习的网址:https://blog.csdn.net/weixin_37517391 ...
- Codeforces Round #376 (Div. 2) F. Video Cards 数学,前缀和
F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- hdu 4746 Mophues 莫比乌斯反演+前缀和优化
Mophues 题意:给出n, m, p,求有多少对a, b满足gcd(a, b)的素因子个数<=p,(其中1<=a<=n, 1<=b<=m) 有Q组数据:(n, m, ...
- NOI题库1799 最短前缀
1799:最短前缀 总时间限制: 1000ms 内存限制: 65536kB 描述 一个字符串的前缀是从该字符串的第一个字符起始的一个子串.例如 "carbon"的字串是: &quo ...
- C. Multi-Subject Competition 思维+前缀和+填表加减复杂度(复杂度计算错误)
题意: 给出n个学生 m类题目 每个人会做s[i]类的题 并且做这个题的能力为r[i] 组成一个竞赛队 要求可以选择一些题目 在竞赛队中 擅长每一个题目的 人数要均等 求max(sigma(r[ ...
- BZOJ5369:[PKUSC2018]最大前缀和(状压DP)
Description 小C是一个算法竞赛爱好者,有一天小C遇到了一个非常难的问题:求一个序列的最大子段和. 但是小C并不会做这个题,于是小C决定把序列随机打乱,然后取序列的最大前缀和作为答案. 小C ...
- CDOJ ABCDE dp(前缀和优化)
题目链接: http://acm.uestc.edu.cn/#/problem/show/1307 ABCDE Time Limit: 1000/1000MS (Java/Others)Memory ...
- HUST 1328 String (字符串前缀子串个数 --- KMP)
题意 给定一个字符串S,定义子串subS[i] = S[0..i],定义C[i]为S中subS[i]的数量,求sigma(C[i])(0<=i<N). 思路 我们以子串结尾的位置来划分阶段 ...
- BZOJ5369 [Pkusc2018]最大前缀和
题意 小C是一个算法竞赛爱好者,有一天小C遇到了一个非常难的问题:求一个序列的最大子段和. 但是小C并不会做这个题,于是小C决定把序列随机打乱,然后取序列的最大前缀和作为答案. 小C是一个非常有自知之 ...
随机推荐
- JVM GC之垃圾收集器
简述 如果说收集算法时内存回收的方法论,那么垃圾收集器就是内存回收的具体实现.这里我们讨论的垃圾收集器是基于JKD1.7之后的Hotspot虚拟机,这个虚拟机包含的所有收集器如图: Serial 收集 ...
- 【redis 学习系列】API的理解与使用(四)
5.集合 集合(set)类型也是用来保存多个字符串元素,但是与列表不一样的是,集合中不允许有重复的元素,并且集合中的元素是无序的,不能通过索引下标获取元素. 如图2-22所示,集合user:1:fol ...
- linux如何离线加载docker镜像?
1. 在已经部署了镜像的机器上获取镜像 1.1 获取镜像名 docker images 1.2 打包选中对应的镜像 docker save <image_name> -o <imag ...
- 用Servlet返回JSON文本动态创建DataGrid
<%@ page language="java" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC & ...
- ES安装的相关
es安装https://www.cnblogs.com/jingping/p/9448099.htmlhttps://blog.csdn.net/zhanyu1/article/details/880 ...
- Threadlocal源码分析以及其中WeakReference作用分析
今天在看Spring 3.x企业应用开发实战,第九章 Spring的事务管理,9.2.2节ThreadLocal的接口方法时,书上有提到Threadlocal的简单实现,我就去看了下JDK1.8的Th ...
- GBK格式字符串右补空格
public class Test2 { public static void main(String[] s) throws IOException { List<User> l ...
- windows下安装redis数据库
第一步: 下载windows版本的Redis:https://github.com/MSOpenTech/redis/releases 这里我下载的是msi安装程序版: 安装时会让你指定Redis使用 ...
- redis开启持久化、redis 数据备份与恢复
redis持久化介绍 https://segmentfault.com/a/1190000015897415 1. 开启aof持久化.以守护进程启动.远程访问先把配置文件拷贝一份到/etc/redi ...
- html5 iphone input 输入法 弹窗将页面顶起 解决办法
给 input 添加失焦事件,然后滚动视图 input.search(type="text",@blur="scrollTop") scrollTop(){ w ...