csu2087(dfs)

csu-2087​

As is known to all, Wells doesn't have a good command of English. As a result, some unfamiliar words, which may cause sadness of Wells, is called tragedy words. In more detail, a word will be defined as a tragedy word, if and only if when it satisfies all following conditions. 

First, it only contain uppercase letter.

Second, it doesn't contain three consecutive vowel(AEIOU) or three consecutive consonant(the other 21 letter).

And last of all, it should contain at least one special tragedy letter 'L'.

Now, you are given a word, which consists of uppercase letter or underline, and you are allow to fill each underline with one uppercase letter. And in order to make fun of Wells, you want to know how many tragedy words you can make in this way.

Input

For each test, only contains a line of one word, which consists of uppercase letter and underline(’_’).

The total length of each word will not exceed 100, and the number of underline(’_’) will not exceed 10.

Output

For each test, print one line, which contains a integer as the total amount of tragedy words you can make.

Notice: the number may be very large and may exceed the 32-bits unsigned integer.

Sample Input

V__K
V_K

Sample Output

10
0

Hint

The vowel means 'A','E','I','O','U'

The consonant means the other 21 letter.

The special tragedy letter 'L' still belongs to consonant.

Of course, the letter here means English letters, not other language letters.

题意:给你一串字符串,“_”上可以填字母,填的规则如下:

1,不能有连续的3个元音和辅音

2,必须有一个L

解析:分情况:

填元音,填辅音,填L,最后判断填完的字符有没有存在一个L,有则满足条件

#include<bits/stdc++.h>
using namespace std;
 
#define e exp(1)
#define pi acos(-1)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
int gcd(int a,int b){return b?gcd(b,a%b):a;}

char s[105];
int t[105],vis[105],cnt,len,j;
ll ans;
void dfs(int x)
{
	if(x==cnt)
	{
		int flag=0;
		for(int i=0; i<len; i++)
		{
			if(s[i]=='L')
			{
				flag=1;
				break;
			}
		}
		if(flag)
		{
			ll temp=1;
			for(int i=0; i<j; i++)
			{
				if(s[t[i]]=='A')temp=temp*5;
				else if(s[t[i]]=='B')temp=temp*20;
				else temp=temp;
			}
			ans+=temp;
			return ;
		}
		return ;
	}
	s[t[x]]='A';
	if ((!((vis[t[x] - 1]) == 1 && (vis[t[x] + 1]) == 1)) &&( !((vis[t[x] - 1]) == 1 && (vis[t[x] - 2]) == 1)) && (!((vis[t[x] + 2]) == 1 && (vis[t[x] + 1]) == 1)))
	{
		vis[t[x]]=1;
		dfs(x+1);
		vis[t[x]]=0;
	}
	s[t[x]]='B';
	if ((!((vis[t[x] - 1]) == 2 && (vis[t[x] + 1]) == 2)) &&( !((vis[t[x] - 1]) == 2 && (vis[t[x] - 2]) == 2)) && (!((vis[t[x] + 2]) == 2 && (vis[t[x] + 1]) == 2)))
	{
		vis[t[x]]=2;
		dfs(x+1);
		vis[t[x]]=0;
	}
	s[t[x]]='L';
	if ((!((vis[t[x] - 1]) == 2 && (vis[t[x] + 1]) == 2)) &&( !((vis[t[x] - 1]) == 2 && (vis[t[x] - 2]) == 2)) && (!((vis[t[x] + 2]) == 2 && (vis[t[x] + 1]) == 2)))
	{
		vis[t[x]]=2;
		dfs(x+1);
		vis[t[x]]=0;
	}
}
int main()
{
	while(~scanf("%s",s))
	{
		mem(t,-1);
		mem(vis,-1);
		len=strlen(s);
		cnt=0;
		ans=0;
		j=0;
		for(int i=0; i<len; i++)
		{
			if(s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U')
			vis[i]=1;
			else if(s[i]=='_')vis[i]=0,t[j++]=i,cnt++;
			else vis[i]=2;
		}
		dfs(0);
		printf("%lld\n",ans);
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值