题目链接:http://codeforces.com/gym/100676/attachments

题意:

给一个字符串,有一些约束条件,两个位置要相同,有一些是问号,求最后有多少种方案回文?

分析:

每一个节点是一个集合,要是不同,有一个是问号,那么这个问号就是确定的(约束条件中,和回文的对称位置),单独的集合,他又是问号,就可以放26个字母了;

 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int MAXN = ; char s[MAXN];
int n,m;
int f[MAXN],flag; int Find(int x)
{
if(x == f[x])
return x;
else return f[x] = Find(f[x]);
} void judge(int x,int y)
{
if(s[x] == s[y])
f[x] = y;
else if(s[x] == '?')
f[x] = y;
else if(s[y] == '?')
f[y] = x;
else flag = true;
} int main()
{
//freopen("in.txt","r",stdin);
int ncase;
scanf("%d",&ncase);
while(ncase--) {
flag = false;
scanf("%d%d%s",&n,&m,s);
for(int i = ;i < n; i++)
f[i] = i;
for(int i = ,j = n-;i < j; i++,j--) {
judge(i,j);
}
for(int i = ;i < m; i++) {
int a,b;
scanf("%d%d",&a,&b);
a--,b--;
judge(Find(a),Find(b));
}
if(flag) {
printf("0\n");
continue;
}
else {
long long ans = ;
for(int i = ;i < n; i++) {
if(f[i] == i && s[i] == '?') {
ans *= ;
ans %= ;
}
}
printf("%lld\n",ans);
}
}
return ;
}

最新文章

  1. js删除数组指定元素
  2. Thinkphp批量添加数据
  3. CentOS 7 做服务器 CentOS 5 做客服机 搭建Apache+php+mysql网页
  4. Java中long类型直接赋值大数字 注意事项
  5. poj 2704 Pascal&#39;s Travels_记忆化搜索
  6. C#中List和数组之间的转换
  7. 3、Spring的AOP详解和案例
  8. LINQ学习系列-----1.3 扩展方法
  9. NFS介绍和安装
  10. python_特殊函数
  11. Pytorch入门实例:mnist分类训练
  12. Spring系列(六) Spring Web MVC 应用构建分析
  13. 【NOI2002】
  14. Win10系列:JavaScript小球运动示例
  15. openstack 资料
  16. VC工程从Win32环境往Win64环境迁移的经验总结
  17. Python3与Python2的差异
  18. 【小程序】text-indent设置
  19. Log Structured Merge Trees (LSM)
  20. target属性用于返回最初触发事件的DOM元素。

热门文章

  1. 搭建element-ui Vue结构
  2. TCP/IP、Http、Https、Socket的区别
  3. Redis未授权访问反弹shell
  4. 2.2 Go 常量与枚举
  5. Django-1 简介
  6. Murano Weekly Meeting 2016.08.09
  7. Neutron命令测试5
  8. axios处理http请求
  9. 关于GPU的 MAKEFILE
  10. HDU 5371——Hotaru&#39;s problem——————【manacher处理回文】