Lazy Spelling Bee

Practice Round APAC test 2017


   Submissions
Lazy Spelling Bee
5pt
Correct
698/1266 users correct (55%)
8pt
Correct
496/685 users correct (72%)
Robot Rock Band
6pt
Correct
480/622 users correct (77%)
14pt
Correct
142/407 users correct (35%)
Not So Random
11pt
Not attempted
204/310 users correct (66%)
20pt
Not attempted
109/158 users correct (69%)
Sums of Sums
8pt
Correct
230/395 users correct (58%)
28pt
Time expired
13/128 users correct (10%)
   Top Scores
Jayam 100
Seter 100
KillswitcherEngag... 100
onepunchman 100
Sumeet.Varma 100
gdragon007 100
libenchao 100
jpsagarm95 100
vaibhav227 100
liubiao2638 100
Practice Mode  Rank: 135 Score: 41

Problem A. Lazy Spelling Bee

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
5 points
Large input
8 points

Problem

In the Lazy Spelling Bee, a contestant is given a target word W to spell. The contestant's answer word A is acceptable if it is the same length as the target word, and the i-th letter of A is either the i-th, (i-1)th, or (i+1)th letter of W, for all i in the range of the length of A. (The first letter of A must match either the first or second letter of W, since the 0th letter of W doesn't exist. Similarly, the last letter of A must match either the last or next-to-last letter of W.) Note that the target word itself is always an acceptable answer word.

You are preparing a Lazy Spelling Bee, and you have been asked to determine, for each target word, how many distinct acceptable answer words there are. Since this number may be very large, please output it modulo 1000000007 (109 + 7).

Input

The first line of the input gives the number of test cases, TT test cases follow; each consists of one line with a string consisting only of lowercase English letters (a throughz).

Output

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the number of distinct acceptable answer words, modulo 109 + 7.

Limits

1 ≤ T ≤ 100.

Small dataset

1 ≤ length of each string ≤ 5.

Large dataset

1 ≤ length of each string ≤ 1000.

Sample


Input 
 

Output 
 
4
ag
aa
abcde
x

Case #1: 4
Case #2: 1
Case #3: 108
Case #4: 1

In sample case #1, the acceptable answer words are aaagga, and gg.

In sample case #2, the only acceptable answer word is aa.

题意:给一个字符串,用这个字符串里面的字母重组一个新字符串,字符种类不可多于原串种类,但可以少于,个数可以不同。且要保证得到的字符串的第i个字符必须等于原串的第i个或i-1个或i+1个。
问这样的字符串有多少个。结果对1000000007取模。
所以每个位置选什么是独立的,直接组合事件乘起来。除了开头结尾的位置都是对于位置i的前一个,当前,后一个位置的字符看有几种就几个选择,开头位置只有当前跟后一个,最后一个是前一个跟当前。
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
const int N = 1210;
typedef long long ll;
using namespace std;
int mod = 1000000007;

char s[N];

int main()
{
  
    freopen("in.txt","r",stdin);
  	freopen("out.txt", "w", stdout);
  	int T, cas = 1;
  	scanf("%d", &T);
  	while (T--)
  	{
  		ll ans = 1;
  		scanf("%s", s);
  		for (int i = 0; s[i]; i++)
  		{
  			int mul = 1;
  			set<char>S;
  			S.insert(s[i]);
  			if (i - 1 >= 0)
  			{
  				S.insert(s[i - 1]);
  			}

  			if (s[i + 1])
  			{
  				S.insert(s[i+1]);
  			}
  			mul = (int)S.size();
  			ans *= mul;
  			ans %= mod;
  		}
  		printf("Case #%d: %lld\n", cas++, ans);
  	}
    return 0;
}


 




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值