codeforces 666C Codeword
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的更多相关文章
- Codeword CodeForces - 666C (字符串计数)
链接 大意:求只含小写字母, 长度为n, 且可以与给定模板串匹配的字符串个数 (多组数据) 记模板串为P, 长为x, 总串为S. 设$f_i$为S为i时的匹配数, 考虑P最后一位的首次匹配位置. 若为 ...
- cf666 C. Codeword 组合数学 离线分块思想
time limit per test 6 seconds memory limit per test 256 megabytes input standard i ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- 6.042 Mathematics for Computer Science
课程信息 6.042 Mathematics for Computer Science
- IDEA tomcat部署
一.前言 1.CATALINA_HOME和CATALINA_BASE两个变量的区别:前者是tomcat的安装目录,后者是tomcat实例的目录.(安装一个tomcat,可以启动多个tomcat ...
- 再说优化MySQL索引
这几天开发尤其重视数据库索引的优化,是一件好事情,开发特意提过来几个要删除的索引,oh!我的佛陀呀!历史上出现过因为评估不到位,删索引引发故障的案例.那么有什么办法可以评估索引是否合理呢? perco ...
- Java如何操作对象(bean)进行动态排序?
原文出自:https://blog.csdn.net/seesun2012 简介如题:Java如何操作对象(bean)进行动态排序?Java实体类(bean)动态排序? 原理:利用反射根据指定的属性值 ...
- centOS 7镜像文件下载
- spring boot2.0
1. Spring boot 简介 1.1 spring boot的三大特性 组件自动装配:Web mvc, Web Flux,JDBC等 激活:@EnableAutoConfiguration 配置 ...
- [javaSE] IO流(对象序列化)
写入 获取ObjectOutputStream对象,new出来,构造参数:FileOutputStream对象目标文件 调用ObjectOutputStream对象的writeObject()方法,参 ...
- String拾遗
简介: String作为日常最常用的类,还是有必要对其中的细节做一些了解的,这篇就结合源码来看看这个常用的类. 一. 总述 类图如下: 从图中可以看到String是实现了 java.io.Serial ...
- axios中的qs
qs是一个npm仓库所管理的包,可通过npm install qs命令进行安装. 1. qs.parse()将URL解析成对象的形式 const Qs = require('qs'); let url ...
- border-radius圆角兼容方案
1.下载ie-css3.htc 2.CSS代码段 box { -moz-border-radius: 15px; /* Firefox */ -webkit-border-radius: 15px; ...