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. Linux环境进程间通信(二): 信号--转载

    http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index1.html http://www.ibm.com/developerworks ...

  2. 如何在CentOS7上安装桌面环境?

    1.安装 GNOME-Desktop 安装GNOME桌面环境 # yum -y groups install "GNOME Desktop" 完成安装后,使用如下命令启动桌面 # ...

  3. 每天一道leetcode203-移除链表的元素

    考试结束,班级平均分只拿到了年级第二,班主任于是问道:大家都知道世界第一高峰珠穆朗玛峰,有人知道世界第二高峰是什么吗?正当班主任要继续发话,只听到角落默默想起来一个声音:”乔戈里峰” 前言 2018. ...

  4. MySQL---3、常用命令大全

    一.连接MySQL 格式: mysql -h主机地址 -u用户名 -p用户密码 1.例1:连接到本机上的MYSQL. 首先在打开DOS窗口,然后进入目录 mysqlbin,再键入命令mysql -ur ...

  5. 如鹏网学习笔记(十五)ASP.NET MVC核心基础笔记

    一.ASP.Net MVC简介 1,什么是ASP.NET MVC? HttpHandler是ASP.net的底层机制,如果直接使用HttpHandler进行开发难度比较大.工作量大.因此提供了ASP. ...

  6. android 模拟器无法启动问题

    很早之前就碰到过Android Studio模拟器无法启动的问题,今天终于尝试去解决了下,下面将我解决的方法记录下. 模拟器报错信息为: emulator: ERROR: x86 emulation ...

  7. Designers, please follow the guidelines

    Skype released big update for its iOS application last week. It brought in a major overhaul of not o ...

  8. Linux(Ubuntu)下MySQL的安装

    1)首先检查系统中是否已经安装了MySQL 在终端里面输入 sudo netstat -tap | grep mysql 若没有反映,没有显示已安装结果,则没有安装.若如下显示,则表示已经安装 2)如 ...

  9. git 之奇技淫巧

    1,git remote prune origin  本地有很多其实早就被删除的远程分支,可以用 git remote prune origin 全部清除掉,这样再 checkout 别的分支时就清晰 ...

  10. .net reflector+reflexil修改编译后的dll文件

    1.用reflector打开相关的dll文件. 2.如果reflector中没有reflexil插件,点击工具栏中的Tools->Add-Ins 3.找到需要修改的文件,双击打开该文件:点击To ...