CSU2087: Tragedy Words

Description

​ 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

这题的意思就是再空格处填字母,要求不能有三个元音字母或者三个辅音字母同时相连,以及字母串中必须有字母L

这题dl说可以用数字dp,但是我不会dp真的是要命,但是这题也可以暴力dfs过时间卡的不紧,但要适当优化,我用A代替元音字母,B代替辅音字母。思想和八皇后的思想相近我觉得,我先在空格处填一个字母,然后看它合不合适如果合适我就去填下一个空格,所有的空格填完了在判断字母串有没有字母L,有的话就可以计算这样填有多少种方案,最后得到总体的数值就能ac了。然后我比赛的时候忘了开long long 导致一直wa ,因为结果开long long 中间计算的值也是需要开long long的,我个菜比总是发现不了自己的错误。

附ac代码:

#include <iostream>
 #include <cstring>
 #include <cstdio>
 #include <algorithm>
 #include <sstream>
 #include <vector>
 #include <set>
 using namespace std;
 char s[105];
 int b[15];//记录_的位置
 int vis[105];
 long long  ans;
 int cnt, j;//cnt为_的个数
 void dfs(int x)
 {
	 if (x == cnt )//如果空格填完了,判断是否满足题意。
	 {
		 int flag = 0;
		 for (int i = 1; i <= strlen(s+1); i++)
		 {
			 if (s[i] == 'L')
			 {
				 flag = 1;
				 break;
			 }
		 }
		 if (flag)
		 {
			 long long temp = 1;//就是这里也要开long long 不开你就wa(微笑脸)。
			 for (int i = 0; i < j; i++)
			 {
				 if (s[b[i]] == 'A')
					 temp = temp * 5;
				 if (s[b[i]] == 'B')
					 temp = temp * 20;
				 else
					 temp = temp;
			 }
			 ans += temp;
			 return;
		 }
		 else
			 return;
	 }
	 s[b[x]] = 'A';
	 if ((!((vis[b[x] - 1]) == 1 && (vis[b[x] + 1]) == 1)) &&( !((vis[b[x] - 1]) == 1 && (vis[b[x] - 2]) == 1)) && (!((vis[b[x] + 2]) == 1 && (vis[b[x] + 1]) == 1)))//判断是否满足没有连续的三个元音
	 {
		 vis[b[x]] = 1;
		 dfs(x + 1);
		 vis[b[x]] = 0;//这里一定要记得变为0,因为不止一组数据满足题意
	 }
	 s[b[x]] = 'B';
	 if ((!((vis[b[x] - 1]) == 2 && (vis[b[x] + 1]) == 2)) && (!((vis[b[x] - 1]) == 2 && (vis[b[x] - 2]) == 2)) && (!((vis[b[x] + 2]) == 2 && (vis[b[x] + 1]) == 2)))//判断是否满足没有三个连续的辅音字母

	 {
		 vis[b[x]] = 2;
		 dfs(x + 1);
		 vis[b[x]] = 0;
	 }
	 s[b[x]] = 'L';
	 if ((!((vis[b[x] - 1]) == 2 && (vis[b[x] + 1]) == 2)) && (!((vis[b[x] - 1]) == 2 && (vis[b[x] - 2]) == 2)) && (!((vis[b[x] + 2]) == 2 && (vis[b[x] + 1]) == 2)))//判断是否满足没有连续的三个辅音字母
	 {
		 vis[b[x]] = 2;
		 dfs(x + 1);
		 vis[b[x]] = 0;
	 }
 }
 int main()
 {
	 while (scanf("%s",s+1)!=EOF)
	 {
		 ans = 0;
		 cnt = 0;
		 j = 0;
		 memset(b, -1, sizeof(b));
		 memset(vis, -1, sizeof(vis));
		 for (int i = 1; i <= strlen(s+1); i++)
		 {
			 if (s[i] == '_')
			 {
				 cnt++;
				 b[j++] = i;
				 vis[i] = 0;
			 }
			 else if (s[i] == 'A' || s[i] == 'E' || s[i] == 'I' || s[i] == 'O' || s[i] == 'U')
				 vis[i] = 1;
			 else
				 vis[i] = 2;
		 }
		 dfs(0);
		 cout << ans << endl;
	 }
	 return 0;
 }



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值