A1371 | [COCI-2017_2018-contest6]#5 Mate
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Little Mate got an array of lowercase letters from the English alphabet as a present from his parents. In order to have at least some use of such a clever present, he decided to use it for finding rhymes when writing his next song.
To find a specific rhyme, Mate wants to select a word of length D that ends with an array of characters XY, i.e. where the next to last letter is X, and the last Y. Mate’s process of selecting a word is by first crossing out some letters in a given sequence, and then merging the letters he didn’t cross out into a single word. He wants to know in how many different ways he can cross out the letters so that he meets the given conditions.
The selection of two words is considered distinct if the sets of positions of the crossed-out letters are different.
To find a specific rhyme, Mate wants to select a word of length D that ends with an array of characters XY, i.e. where the next to last letter is X, and the last Y. Mate’s process of selecting a word is by first crossing out some letters in a given sequence, and then merging the letters he didn’t cross out into a single word. He wants to know in how many different ways he can cross out the letters so that he meets the given conditions.
The selection of two words is considered distinct if the sets of positions of the crossed-out letters are different.
输入格式
The first line of input contains an array of lowercase letters of the English alphabet S (2 ≤ |S|
≤ 2000).
The second line of input contains the integer Q (1 ≤ Q ≤ 500 000), the number of different rhymes for which Mate needs to select words.
Each of the following Q lines contains the integer D (2 ≤ D ≤ |S|) and an array of lowercase letters of the English alphabet XY from the task
≤ 2000).
The second line of input contains the integer Q (1 ≤ Q ≤ 500 000), the number of different rhymes for which Mate needs to select words.
Each of the following Q lines contains the integer D (2 ≤ D ≤ |S|) and an array of lowercase letters of the English alphabet XY from the task
输出格式
The i^th out of Q lines must contain the required number of ways for the i^th rhyme. Since that number can be quite large, output only the value modulo 1 000 000 007.
输入输出样例
输入 #1
banana 3 2 na 3 ba 4 nn
输出 #1
3 0 1
输入 #2
malimateodmameitate 3 10 ot 7 aa 3 me
输出 #2
2 464 56
In test cases worth 40% of total points, it will hold |S| ≤ 50.
In test cases worth an additional 40% of total points, it will hold |S| ≤ 200.
Clarification of the first test case:
Word of length 2 that ends with “na” can be obtained in the following ways:
b a n a n a, b a n a n a, b a n a n a.
In test cases worth an additional 40% of total points, it will hold |S| ≤ 200.
Clarification of the first test case:
Word of length 2 that ends with “na” can be obtained in the following ways:
b a n a n a, b a n a n a, b a n a n a.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted