16年北京现场赛的题,全场过的队30+。

初看只知道 O(N^2logK)的暴力,以为是什么变换。

仔细发现活用 二项式定理 就行。

 #include <bits/stdc++.h>
using namespace std;
#define fst first
#define scd second
#define pb(x) push_back((x))
#define mkp(x,y) make_pair((x),(y))
#define ist(x) insert((x))
typedef long long ll;
typedef pair<int ,int > pii;
typedef pair<ll ,ll > pll;
typedef vector< int > vi;
ll gcd(ll a,ll b){ return b==?a:gcd(b,a%b);}
ll qPow(ll a,ll b,ll mod){ ll ret=1ll;while(b){ if(b&) ret=ret*a%mod;a=a*a%mod;b>>=;} return ret; } const ll mod=1e9+;
const int maxn=5e4+;
ll P[maxn][]; // P[i][k] 代表 前i个数字之和的k次方
ll Pre[maxn][];// Pre[i][k] 代表 前i个P[i][k]的和
ll F[],INV[];
char raw[maxn];
int N,K; void init(){
P[][]=;
for(int i=;i<=N;++i){
P[i][]=;
P[i][]=(P[i-][]+raw[i-]-'')%mod;
for(int j=;j<=K;++j)
P[i][j]=P[i][j-]*P[i][]%mod;
} Pre[][]=;// 0^0 =1
for(int j=;j<=K;++j){
for(int i=;i<=N;++i)
Pre[i][j]=(Pre[i-][j]+P[i][j])%mod;
}
} ll getC(int i,int j){
if(j==) return 1ll;
return F[i]*INV[i-j]%mod*INV[j]%mod;
} int main(){ F[]=1ll;
for(ll i=;i<=;++i)
F[i]=F[i-]*i%mod;
INV[]=qPow(F[],mod-,mod);
for(ll i=;i>=;i--)
INV[i]=(i+)*INV[i+]%mod; int Tests;
scanf("%d",&Tests);
while(Tests--){
scanf("%d%d",&N,&K);
scanf("%s",raw);
init();
ll ans;
for(int i=;i<=N;++i){
ans=0ll;
for(int j=;j<=K;++j){
if(j&)
ans=(ans-getC(K,j)*P[i][K-j]%mod*Pre[i-][j]%mod+mod)%mod;
else
ans=(ans+getC(K,j)*P[i][K-j]%mod*Pre[i-][j]%mod)%mod;
}
printf("%lld%c",ans,i==N?'\n':' ');
}
}
return ;
}

(代码写的常数有点大,应该是mod多了,,,

A Boring Problem UVALive - 7676的更多相关文章

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

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

  2. hihoCoder 1430 : A Boring Problem(一琐繁题)

    hihoCoder #1430 : A Boring Problem(一琐繁题) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 As a ...

  3. 【XSY1642】Another Boring Problem 树上莫队

    题目大意 给你一棵\(n\)个点的树,每个点有一个颜色\(c_i\),每次给你\(x,y,k\),求从\(x\)到\(y\)的路径上出现次数第\(k\)多的颜色的出现次数 \(n,q\leq 1000 ...

  4. Joseph's Problem UVALive - 3521(等差数列的应用)

    题意:给定n, k,求出∑ni=1(k mod i) 思路:由于n和k都很大,直接暴力是行不通的,然后在纸上画了一些情况,就发现其实对于k/i相同的那些项是形成等差数列的,于是就可以把整个序列进行拆分 ...

  5. 北京区域赛I题,Uva7676,A Boring Problem,前缀和差分

    转载自https://blog.csdn.net/weixin_37517391/article/details/83821752 题解 其实这题不难,只要想到了前缀和差分就基本OK了. 我们要求的是 ...

  6. UVALive - 3713 - Astronauts(图论——2-SAT)

    Problem   UVALive - 3713 - Astronauts Time Limit: 3000 mSec Problem Description Input The input cont ...

  7. UVALive - 3211 - Now or later(图论——2-SAT)

    Problem   UVALive - 3211 - Now or later Time Limit: 9000 mSec Problem Description Input Output Sampl ...

  8. UVALive - 4287 - Proving Equivalences(强连通分量)

    Problem   UVALive - 4287 - Proving Equivalences Time Limit: 3000 mSec Problem Description Input Outp ...

  9. UVALive - 5135 - Mining Your Own Business(双连通分量+思维)

    Problem   UVALive - 5135 - Mining Your Own Business Time Limit: 5000 mSec Problem Description John D ...

随机推荐

  1. 数据库-PLSQL登录oracle数据库卡死(未响应)解决方法

    上次重装系统后重新安装了oracle和PLSQL,哪知道PLSQL登录不了,一登录就未响应,但如果不登录就不卡死,直接就进去了.在网上查了很多解决方法,都没有用. 后来在百度文库找到解决办法,重启Or ...

  2. 序列化模块_pickle

    序列化: 把不能够直接存储的数据变成字节流(bytes)保存在文件, 进行持久化存储 反序列化: 任何数据都可以转成字节流(bytes)进行存储: 1. dumps 把任意对象序列化 li = [1, ...

  3. linux安装mysql8.0及开启远程访问

    第一步:获取mysql8.0的yum源 进入mysql官网获取RPM包下载地址 https://dev.mysql.com/downloads/repo/yum/     点击下载后, 右键复制链接地 ...

  4. WordPress版微信小程序安装使用说明

    昨天在群里,有刚刚使用WordPress版微信小程序朋友,在问安装过程中的问题,这些问题是经常被问到,这至少说明两个问题: 1.我开发的程序安装和使用不够简易,无法通过简单的配置就可以使用,特别是如果 ...

  5. 对Unity一个Shader编译Bug的分析(Unrecognized sampler 'samplerunity_lightmap)

    写在前面 Unity的用户量越来越大,越来越有钱,这几年摊子也铺的越来越大,所以各个版本总是有很多Bug.对于一些Bug官方在ReleaseNote里的说明是很不详细的,而对于一些渲染相关的Bug,有 ...

  6. C#导出 Excel 时, 生成 CheckBox 控件

    在使用 Microsoft.Office.Interop.Excel 组件导出Excel 表格时,要把导出前的  CheckBox 控件一同导出到 excel 表格中,对于这个功能 看似很简单,但 M ...

  7. apue第九章之孤儿进程组

    1. 为什么会有孤儿进程组的概念,APUE没直接写,但是GNU有规定: 孤儿进程组不可以获得终端,这是为了保证控制进程死掉后他的终端可以安全分配给新session.posix要求向新孤儿进程组中停止状 ...

  8. LeetCode 105. Construct Binary Tree from Preorder and Inorder Traversal 由前序和中序遍历建立二叉树 C++

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  9. 目标检测——Faster R_CNN使用smooth L1作为bbox的回归损失函数原因

    前情提要—— 网上关于目标检测框架——faster r_cnn有太多太好的博文,这是我在组会讲述faster r_cnn这一框架时被人问到的一个点,当时没答上来,于是会下好好百度和搜索一下研究了一下这 ...

  10. React事件处理

    function ActionLink() { function handleClick(e) { e.preventDefault(); console.log('链接被点击'); } return ...