HPrefix Sum

study from : https://blog.csdn.net/mitsuha_/article/details/81774727

k较小。分离x和k。

另外的可能:求a[k][x],x不确定,想到的是求sum(a[k][1]+a[k][2]+...+a[k][x]),树状数组 sum(x)-sum(x-1)。这题用不上。

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iostream>
using namespace std; #define ll long long const int maxn=1e5+;
const int maxk=+;
const int inf=1e9;
const ll mod=1e9+;
const double eps=1e-; ll f[maxk][maxn],mul[maxn],chu[maxn];
int n,k; ll C(int x,int y)
{
if (x<)
{
x=y--x;
return (y&?-:)*mul[x]*chu[x-y]%mod*chu[y]%mod;
}
if (x<y)
return ;
return mul[x]*chu[x-y]%mod*chu[y]%mod;
} ll _pow(ll a,ll b)
{
ll y=;
while (b)
{
if (b &)
y=y*a%mod;
a=a*a%mod;
b>>=;
}
return y;
} void update(int x,ll y,int j)
{
while (x<=n)
{
f[j][x]=(f[j][x]+y)%mod;
x+=x&-x;
}
} ll cal(int x,int j)
{
ll sum=;
while (x)
{
sum=(sum+f[j][x])%mod;
x-=x&-x;
}
return sum;
} int main()
{
int m,i,j,mode,x;
ll sum=,y;
scanf("%d%d%d",&n,&m,&k);
k--;
mul[]=;
for (i=;i<=n;i++)
mul[i]=mul[i-]*i%mod;
chu[n]=_pow(mul[n],mod-);
for (i=n-;i>=;i--)
chu[i]=chu[i+]*(i+)%mod;
while (m--)
{
scanf("%d",&mode);
if (mode)
{
scanf("%d",&x);
sum=;
for (j=;j<=k;j++)
sum=(sum+C(x,j)*cal(x,j))%mod;
printf("%lld\n",sum);
}
else
{
scanf("%d%lld",&x,&y);
for (j=;j<=k;j++)
update(x,C(k-x,k-j)*y%mod,j);
}
}
return ;
}
/*
4 11 3
0 3 1
1 4
*/

CGambling

 #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iostream>
using namespace std; #define ll long long const int maxn=1e5+;
const int inf=1e9;
const double eps=1e-;
const ll mod=1e9+; ll mul[maxn<<],chu[maxn<<]; ll _pow(ll a,ll b)
{
ll y=;
while (b)
{
if (b&)
y=y*a%mod;
a=a*a%mod;
b>>=;
}
return y;
} ll C(ll x,ll y)
{
return mul[x]*chu[x-y]%mod*chu[y]%mod;
} int main()
{
int n,i,j,a;
scanf("%d",&n);
mul[]=;
for (i=;i<=*n;i++)
mul[i]=mul[i-]*i%mod;
chu[*n]=_pow(mul[*n],mod-);
for (i=*n-;i>=;i--)
chu[i]=chu[i+]*(i+)%mod;
i=,j=;
while (~scanf("%d",&a))
{
printf("%lld\n",_pow(,+i+j)*C(*n--i-j,n-i-)%mod);
i+=(a==),j+=(a==);
}
return ;
}
/* */

GLongest Common Subsequence

牛客网暑期ACM多校训练营 第九场的更多相关文章

  1. 牛客网暑期ACM多校训练营(第四场):A Ternary String(欧拉降幂)

    链接:牛客网暑期ACM多校训练营(第四场):A Ternary String 题意:给出一段数列 s,只包含 0.1.2 三种数.每秒在每个 2 后面会插入一个 1 ,每个 1 后面会插入一个 0,之 ...

  2. 牛客网暑期ACM多校训练营(第五场):F - take

    链接:牛客网暑期ACM多校训练营(第五场):F - take 题意: Kanade有n个盒子,第i个盒子有p [i]概率有一个d [i]大小的钻石. 起初,Kanade有一颗0号钻石.她将从第1到第n ...

  3. 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?

    牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...

  4. 牛客网 暑期ACM多校训练营(第一场)A.Monotonic Matrix-矩阵转化为格子路径的非降路径计数,Lindström-Gessel-Viennot引理-组合数学

    牛客网暑期ACM多校训练营(第一场) A.Monotonic Matrix 这个题就是给你一个n*m的矩阵,往里面填{0,1,2}这三种数,要求是Ai,j⩽Ai+1,j,Ai,j⩽Ai,j+1 ,问你 ...

  5. 牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献)

    牛客网暑期ACM多校训练营(第三场)H Diff-prime Pairs (贡献) 链接:https://ac.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy ha ...

  6. 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)

    2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...

  7. 牛客网暑期ACM多校训练营(第七场)Bit Compression

    链接:https://www.nowcoder.com/acm/contest/145/C 来源:牛客网 题目描述 A binary string s of length N = 2n is give ...

  8. 牛客网暑期ACM多校训练营(第一场) - J Different Integers(线段数组or莫队)

    链接:https://www.nowcoder.com/acm/contest/139/J来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 524288K,其他语言1048 ...

  9. 牛客网暑期ACM多校训练营(第九场) A题 FWT

    链接:https://www.nowcoder.com/acm/contest/147/A来源:牛客网 Niuniu has recently learned how to use Gaussian ...

随机推荐

  1. python爬虫scrapy之rules的基本使用

    Link Extractors Link Extractors 是那些目的仅仅是从网页(scrapy.http.Response 对象)中抽取最终将会被follow链接的对象。 Scrapy默认提供2 ...

  2. python学习笔记(11)--数据组织的维度

    数据的操作周期 存储  -- 表示 -- 操作 一维数据表示 如果数据有序,可以使用列表[]:如果数据没有顺序,可以使用集合{} 一维数组存储 存储方式一:空格分隔 ,使用一个或多个空格分隔进行分隔, ...

  3. SSM+shiro,所有配置文件,详细注释版,自用

    spring配置文件applicationContext.xml,放在resources下 <?xml version="1.0" encoding="UTF-8& ...

  4. change safari user agent

    defaults write com.apple.safari customuseragent '"mozilla/5.0 (iphone; cpu iphone os 8_1 like m ...

  5. Git要点

    前面的话 本文将总结Git要点 版本管理工具 [作用] 1.备份文件 2.记录历史 3.回到过去 4.对比差异 [分类] 1.手动版本控制(又叫人肉VCS) 2.LVCS 本地 3.CVCS 集中式( ...

  6. Vmware 控制脚本

    #_*_ coding:utf8 _*_ import sys,time import yaml import re import os import ssl import random import ...

  7. Codeforces Round #443 Div. 1

    A:考虑每一位的改变情况,分为强制变为1.强制变为0.不变.反转四种,得到这个之后and一发or一发xor一发就行了. #include<iostream> #include<cst ...

  8. BZOJ1001 洛谷4001 [BJOI2006]狼抓兔子 题解

    题目 这个题目有多种解法,这个题也是一个比较经典的题了,正是因为他的多样的做法,这个题主要难在建图和优化,因为这是一个网格图,所以spfa肯定过不去,所以用最短路解法的话,只能用dij,而网络流也是要 ...

  9. HBase电子书

    HBase 不睡觉书  https://pan.baidu.com/s/1d4u7pPAu_B3sW5w9x1ARdA HBase2018年年度总结 https://pan.baidu.com/s/1 ...

  10. Marriage Match II HDU - 3081(二分权值建边)

    题意: 有编号为1~n的女生和1~n的男生配对 首先输入m组,a,b表示编号为a的女生没有和编号为b的男生吵过架 然后输入f组,c,d表示编号为c的女生和编号为d的女生是朋友 进行配对的要求满足其一即 ...