codeforces 666C Codeword

题意

q个询问,一种询问是给你一个字符串,还有一种是问长度为n的,包含当前字符串为子序列的字符串有多少个。

题解

容易写出式子,但是不好化简。

观察一下可以知道q个询问的字符串长度也就根号种。

代码

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
//--- const int N = 101010, P = 1e9+7; int pw[N], jc[N], in[N], ans[N];
vector<pii> Q[N]; inline int mul(int a, int b) {
return a * 1ll * b % P;
}
inline int add(int a, int b) {
int res = a+b;
if(res >= P) res -= P;
return res;
} inline int kpow(int a, int b) {
int res = 1;
while(b) {
if(b&1) res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
} inline void init() {
pw[0] = 1;
rep(i, 1, N) pw[i] = mul(pw[i-1], 25);
jc[0] = 1;
rep(i, 1, N) jc[i] = mul(jc[i-1], i);
in[N-1] = kpow(jc[N-1], P-2);
for(int i = N-2; ~i; --i) in[i] = mul(in[i+1], i+1);
} inline int C(int n, int m) {
if(n < m) return 0;
return mul(jc[n], mul(in[m], in[n-m]));
} int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
init();
int n, m, q;
string s;
cin >> q >> s;
m = sz(s);
rep(i, 0, q) {
int x;
cin >> x;
if(x == 1) {
cin >> s;
m = sz(s);
} else {
cin >> n;
Q[m].pb(mp(n, i));
}
}
rep(m, 0, N) if(sz(Q[m])) {
sort(all(Q[m]));
int i = m, res = 1;
for(auto t : Q[m]) {
int n = t.fi;
while(i < n) {
++i;
res = mul(res, 26);
res = add(res, mul(C(i-1, m-1), pw[i - m]));
}
ans[t.se] = n >= m ? res : 0;
++ans[t.se];
}
}
rep(i, 0, q) if(ans[i]) {
cout << ans[i]-1 << endl;
}
return 0;
}

codeforces 666C Codeword的更多相关文章

  1. Codeword CodeForces - 666C (字符串计数)

    链接 大意:求只含小写字母, 长度为n, 且可以与给定模板串匹配的字符串个数 (多组数据) 记模板串为P, 长为x, 总串为S. 设$f_i$为S为i时的匹配数, 考虑P最后一位的首次匹配位置. 若为 ...

  2. cf666 C. Codeword 组合数学 离线分块思想

                      time limit per test 6 seconds memory limit per test 256 megabytes input standard i ...

  3. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  4. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  5. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  6. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  7. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  8. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  9. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

随机推荐

  1. Debian9安装桌面环境

    更新安装源 apt-get update 安装 x-window apt-get install x-window-system-core 安装 gnomeapt-get install gnome- ...

  2. *2.2.3 加入objection机制

    在上一节中,虽然输出了“main_phase is called”,但是“data is drived”并没有输出.而main_phase是一个完整的任务,没有理由只执行第一句,而后面的代码不执行.看 ...

  3. Training Logisches Denken

    1.Das Begriff 1.1 Die Arten von Begriff 1.1.1 alleines Begriff,universales Begriff,Leeres Begriff: A ...

  4. ASP.NET MVC Core的ViewComponent

    MVC Core新增了ViewComponent的概念,直接强行理解为视图组件,用于在页面上显示可重用的内容,这部分内容包括逻辑和展示内容,而且定义为组件那么其必定是可以独立存在并且是高度可重用的. ...

  5. H5+MUI上传文件

    应用场景:MUI+H5+WEBAPI 今天在给我外甥女调手机端上传图片的时候,发现他是直接调用的MUI下的api,直接调取相册或者相机,到最后只看见了一个文件的路径,所以以前写的上传文件就不太好套上去 ...

  6. C# 提高必备精品--你所需要的NET笔记

    一. 交换两个数据的值: 1.  //创建一个临时变量 //int temp; //temp = num1; ////用num2的值覆盖掉num1 //num1 = num2; ////将存储在临时变 ...

  7. GIT 基础-基础命令

    环境 centos7 1.安装 #yum install git 2.创建本地仓库 ( 这里用 /www/git) 这里里有个隐藏的文件夹 ```.git``` 为git仓库的配置文件夹, 不可随意修 ...

  8. 使用jQuery的validation插件实现表单校验

    前端表单校验: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  9. 【Android】15.0 UI开发(六)——列表控件RecyclerView的网格布局排列实现

    1.0 列表控件RecyclerView的网格布局排列实现,关键词GridLayoutManager. LinearLayoutManager 实现顺序布局 GridLayoutManager 实现网 ...

  10. HTML表单相关

    表单:<input type="text" name="" value="" size="显示字符数" maxle ...