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的更多相关文章

  1. A Boring Problem UVALive - 7676 (二项式定理+前缀和)

    题目链接: I - A Boring Problem UVALive - 7676 题目大意:就是求给定的式子. 学习的网址:https://blog.csdn.net/weixin_37517391 ...

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

  3. hdu 4746 Mophues 莫比乌斯反演+前缀和优化

    Mophues 题意:给出n, m, p,求有多少对a, b满足gcd(a, b)的素因子个数<=p,(其中1<=a<=n, 1<=b<=m) 有Q组数据:(n, m, ...

  4. NOI题库1799 最短前缀

    1799:最短前缀 总时间限制: 1000ms 内存限制: 65536kB 描述 一个字符串的前缀是从该字符串的第一个字符起始的一个子串.例如 "carbon"的字串是: &quo ...

  5. C. Multi-Subject Competition 思维+前缀和+填表加减复杂度(复杂度计算错误)

    题意: 给出n个学生 m类题目 每个人会做s[i]类的题 并且做这个题的能力为r[i]  组成一个竞赛队 要求可以选择一些题目  在竞赛队中 擅长每一个题目的 人数要均等  求max(sigma(r[ ...

  6. BZOJ5369:[PKUSC2018]最大前缀和(状压DP)

    Description 小C是一个算法竞赛爱好者,有一天小C遇到了一个非常难的问题:求一个序列的最大子段和. 但是小C并不会做这个题,于是小C决定把序列随机打乱,然后取序列的最大前缀和作为答案. 小C ...

  7. CDOJ ABCDE dp(前缀和优化)

    题目链接: http://acm.uestc.edu.cn/#/problem/show/1307 ABCDE Time Limit: 1000/1000MS (Java/Others)Memory ...

  8. HUST 1328 String (字符串前缀子串个数 --- KMP)

    题意 给定一个字符串S,定义子串subS[i] = S[0..i],定义C[i]为S中subS[i]的数量,求sigma(C[i])(0<=i<N). 思路 我们以子串结尾的位置来划分阶段 ...

  9. BZOJ5369 [Pkusc2018]最大前缀和

    题意 小C是一个算法竞赛爱好者,有一天小C遇到了一个非常难的问题:求一个序列的最大子段和. 但是小C并不会做这个题,于是小C决定把序列随机打乱,然后取序列的最大前缀和作为答案. 小C是一个非常有自知之 ...

随机推荐

  1. google中select添加onclick

    有下拉跳转框如下所示: <select name="page" size="1" > <option onclick="refurb ...

  2. JavaWeb_(Hibernate框架)Hibernate中数据查询语句Criteria基本用法

    Criteria进行数据查询与HQL和SQL的区别是Criteria完全是面向对象的方式在进行数据查询,将不再看到有sql语句的痕迹,使用Criteria 查询数据包括以下步骤: 1. 通过sessi ...

  3. 2016多校7.14 Warmup 题解

    先讲1007,是一个数位dp,询问一个区间内,各位数的和是一个素数的数字的个数.其实我并不会数位dp,这题直接套用了上次多校lyf队长的dp代码,改了点返回参数没想到直接AC了.代码如下: #incl ...

  4. WebSSH2 界面ssh(转载)

    工具:Virtual Machines14.1 系统环境:CentOS 7 64位 (2个)   IP:192.168.163.138 IP:192.168.163.141 概述:在138系统中安装部 ...

  5. yolo image.c

    void draw_detections(image im, detection *dets, int num, float thresh, char **names, image **alphabe ...

  6. logserver 日志服务项目发布

    logserver是使用logback.light-4j.commons-exec等构建的简单日志服务,参考项目logbackserver和light4j,支持跟踪日志.分页查看.搜索定位.下载文件等 ...

  7. mac 配置apache

    Apache配置 对httpd.conf文件的配置.首先打开 /etc/apache2/httpd.conf文件,也就是Apache2.4的相关配置文件. 连接php 首先我们将相应的PHP版本配置进 ...

  8. python查找鞍点

    问题:对于给定5X5的整数矩阵,设计算法查找出所有的鞍点的信息(包括鞍点的值和行.列坐标,坐标从1开始). 提示:鞍点的特点:列上最小,行上最大. 思路:求出每一行的最大值,将行号.列号.值存入列表中 ...

  9. Go项目的测试代码2(项目运用)

    上一篇文章介绍了最基本的测试代码的写法.Go项目的测试代码(基础) 这里简单的共享一下我在项目中使用的方式. 项目结构 我们实际项目中, 结构简单地分了控制层controllers和模块层models ...

  10. 【Makefile】Makefile中的常用函数简介

    1. subst函数 格式:$(subst <from>, <to>, <text>)功能:把字串<text>中的<from>字符串替换成& ...