A Boring Problem UVALive - 7676 (二项式定理+前缀和)
题目链接:
I - A Boring Problem
UVALive - 7676
题目大意:就是求给定的式子。
学习的网址:https://blog.csdn.net/weixin_37517391/article/details/83821752
思路:证明过程在上面的博客中说了,大体意思就是预处理出两个前缀和,然后通过二项式定理化简式子就好了。
AC代码:
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn = 2e5+;
const int mod = 1e9+;
ll c[+][+];
char str[maxn];
ll s1[+][maxn],s2[+][maxn];
ll ind(int t1,int t2)
{
if(t2&)
return -1ll;
return 1ll;
}
void init()
{
c[][]=1ll;
for(int i=; i<=; i++)
{
c[i][]=1ll;
for(int j=; j<=i; j++)
{
c[i][j]=(c[i-][j]+c[i-][j-])%mod;
}
}
}
int main()
{
init();
int T;
scanf("%d",&T);
while(T--)
{
int n,k;
scanf("%d %d",&n,&k);
scanf("%s",str);
for(int i=; i<=n; i++)
{
s1[][i]=1ll;
}
for(int i=; i<=n; i++)
{
s1[][i]=(s1[][i-]+(ll)(str[i-]-''));
}
for(int i=; i<=k; i++)
{
for(int j=; j<=n; j++)
{
s1[i][j]=s1[i-][j]*s1[][j]%mod;
}
}
s2[][]=1ll;
for(int i=; i<=n; i++)
{
for(int j=; j<=k; j++)
{
s2[j][i]=(s2[j][i-]+s1[j][i])%mod;
}
}
for(int i=; i<=n; i++)
{
ll ans=;
for(int j=; j<=k; j++)
{
ll tmp=c[k][j]*s1[j][i]%mod*s2[k-j][i-]%mod;
if(ind(-,k-j)==1ll)
ans=(ans+tmp)%mod;
else
ans=(ans-tmp+mod)%mod;
}
if(i!=)
printf(" ");
printf("%lld",ans);
}
printf("\n");
}
return ;
}
A Boring Problem UVALive - 7676 (二项式定理+前缀和)的更多相关文章
- A Boring Problem UVALive - 7676
16年北京现场赛的题,全场过的队30+. 初看只知道 O(N^2logK)的暴力,以为是什么变换. 仔细发现活用 二项式定理 就行. #include <bits/stdc++.h> us ...
- hihoCoder 1430 : A Boring Problem(一琐繁题)
hihoCoder #1430 : A Boring Problem(一琐繁题) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 As a ...
- 北京区域赛I题,Uva7676,A Boring Problem,前缀和差分
转载自https://blog.csdn.net/weixin_37517391/article/details/83821752 题解 其实这题不难,只要想到了前缀和差分就基本OK了. 我们要求的是 ...
- 二项式定理+前缀Sigma
https://hihocoder.com/problemset/problem/1430 思路: 要用前缀去推Sigma总公式,比较方便.https://blog.csdn.net/weixin_3 ...
- HDU 5687 Problem C ( 字典树前缀增删查 )
题意 : 度熊手上有一本神奇的字典,你可以在它里面做如下三个操作: 1.insert : 往神奇字典中插入一个单词 2.delete: 在神奇字典中删除所有前缀等于给定字符串的单词 3.search: ...
- 【XSY1642】Another Boring Problem 树上莫队
题目大意 给你一棵\(n\)个点的树,每个点有一个颜色\(c_i\),每次给你\(x,y,k\),求从\(x\)到\(y\)的路径上出现次数第\(k\)多的颜色的出现次数 \(n,q\leq 1000 ...
- Joseph's Problem UVALive - 3521(等差数列的应用)
题意:给定n, k,求出∑ni=1(k mod i) 思路:由于n和k都很大,直接暴力是行不通的,然后在纸上画了一些情况,就发现其实对于k/i相同的那些项是形成等差数列的,于是就可以把整个序列进行拆分 ...
- UVALive - 3713 - Astronauts(图论——2-SAT)
Problem UVALive - 3713 - Astronauts Time Limit: 3000 mSec Problem Description Input The input cont ...
- UVALive - 3211 - Now or later(图论——2-SAT)
Problem UVALive - 3211 - Now or later Time Limit: 9000 mSec Problem Description Input Output Sampl ...
随机推荐
- 在IIS上部署(托管).NET Core站点
部署教程 操作系统要求 Windows 7 或更高版本 Windows Server 2008 R2 或更高版本 依赖的组件 Runtime & Hosting Bundle image. ...
- P1546 最短网络 Agri-Net题解(克鲁斯卡尔)
P1546 最短网络 Agri-Net 那么这个题是一道最小生成树的板子题 在此讲解kruskal克鲁斯卡尔方法: 原理: 并查集在这里被用到: 众所周知:树满足这样一个定理:如果 图 中有n个节点并 ...
- Java高级篇(四)——反射
之前写到了设计模式的代理模式,因为下一篇动态代理等内容需要用到反射的知识,所以在之前Java篇的基础上再写一篇有关反射的内容,还是以实际的程序为主,了解反射是做什么的.应该怎么用. 一.什么是反射 反 ...
- Linux+Shell常用命令总结
因为自己不经常使用linux的命令行工具,但是mac的终端还是经常使用的,有些命令总是要想一会或者百度一下才知道怎么用,抽时间整理了一下常用的命令,作为笔记. 常用命令 查看文件操作: ls :列出当 ...
- cpu_ops、suspend_ops、arm_idle_driver以及machine_restart/machine_power_off到底层PSCI Firmware分析
在内核中针对的cpu的操作,比如arm_cpuidle_init.arm_cpuidle_suspend.boot_secondary.secondary_start_kernel.op_cpu_di ...
- 随心测试_软测基础_002_<测试工程师_核心技能体系>
测试工程师核心技能体系构成 测试基础体系:[对象——>方法——>流程].[测试活动类型——>质量] 测试分析体系:[测试对象分析]——>[测试设计(计划.数据.用例.文档)] ...
- pyspider煎蛋无聊图爬取
命令行pyspider,启动pyspider. web预览界面太小,解决方法:找到pyspider的安装路径下的debug.min.css,修改css代码: 将其中的iframe{border-wid ...
- pci设备驱动相关
pci 设备注册及查找: https://www.cnblogs.com/image-eye/archive/2012/02/15/2352912.html PFN https://nieyong.g ...
- 使用lombok自动生成链式调用
本文转载:使用 Lombok 自动生成 Getter and Setter
- Codeforces878 A. Short Program
题目类型:位运算 传送门:>Here< 题意:给出\(N\)个位运算操作,要求简化操作数量,使之结果不受影响(数据在1023之内) 解题思路 我们发现数字的每一位是独立的.也就是说,每一个 ...