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 ...
随机推荐
- CSS选择器详解(二)通用选择器和高级选择器
目录 通用选择器 高级选择器 子选择器 相邻兄弟选择器 属性选择器 通用选择器 通用选择器可以选择页面上的所有元素,并对它们应用样式,用 * 来表示. 语法: * { property1: value ...
- 2016年学习JavaScript是怎样的一种体验(转)
转自:http://www.zcfy.cc/article/how-it-feels-to-learn-javascript-in-2016-hacker-noon-1871.html 在这篇文章的写 ...
- Uboot流程分析
1. uboot的配置分析 1).配置入口分析 首先分析配置: 从make mx6dl_sabresd_android_config可知配置项,搜索Makefile: mx6solo_sabresd_ ...
- maven 错误:读取 xxx.jar 时出错;invalid LOC header (bad signature) 1 错误
reqHeader:{Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8, Upgrade-Insecure- ...
- SQL SERVER学习2——数据库设计
数据库设计是数据库知识中比较重要的部分,我们需要了解数据库设计的基本步骤,E-R图的画法. 数据库设计的基本概述 检验一个数据库设计好坏的标准就是,看他是否能够方便的执行各种数据检索和处理操作,并且有 ...
- 01 使用JavaScript原生控制div属性
写在前面: 因对前端开发感兴趣,于是自学前端技术,现在已经会HTML.CSS.JavaScript基础技术.但水平处于小白阶段,在网上找一些小项目练练手,促进自己的技术成长.文章记录自己的所思所想,以 ...
- MySQL查询小数点位数
怎么查询某个字段中小数有几位? MySQL数据库: 通过下面sql就可以查出来,有2位col*100,有3位col*1000,一次类推: ) 备注:floor:函数只返回整数部分,小数部分舍弃. Or ...
- uestc 1709 Binary Operations 位运算的灵活运用
Binary Operations Time Limit: 2000 ms Memory Limit: 65535 kB Solved: 56 Tried: 674 Description B ...
- CodeForces 616A(水题)
while(t--) 最后结果t=-1 #include <iostream> #include <string> #include <cstring> #incl ...
- Win10系统安装vmware workstation 12后没有桥接网卡怎么办
原文 vmware workstation是一款虚拟机计算机软件,可以同时运行不同的操作系统,然而有win10系统用户在安装vmware workstation 12之后,却发现网络连接里面没有桥接网 ...