题目链接:

http://codeforces.com/problemset/problem/653/B

题意:

要求你构造一个长度为n的字符串使得通过使用m个操作,最终获得字符a。已知第i个操作将字符串中开头的字符串ai换成字符bi,长度减少1。问一共有多少种字符串构造方法。

分析:

直接dfs一下就好啦~~~

代码:

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 105;
char a[maxn][2], b[maxn];
int n,q;
int dfs(int pos, int cnt)
{
if(cnt <= 0) return 1;
int ans = 0;
for(int i= 0; i < q; i++){
if(b[i] == a[pos][0]){
ans += dfs(i, cnt - 1);
}
}
return ans;
}
int main (void)
{
cin>>n>>q;
int pos;
long long ans = 0;
vector<int>v;
for(int i = 0; i < q; i++){
cin>>a[i][0]>>a[i][1]>>b[i];
if(b[i] == 'a') v.push_back(i);
}
for(int i = 0; i < v.size(); i++){
ans += dfs(v[i], n - 2);
}
cout<<ans<<endl;
}

最新文章

  1. IO多路复用之poll总结
  2. tyvj1106 登山
  3. drdb
  4. 1106c语言语法树
  5. Table of Contents - 设计模式
  6. android开发3:四大基本组件的介绍与生命周期
  7. 朱丽叶—Cuda+OSG
  8. [题解]bzoj 3223 文艺平衡树
  9. mysql数据库表结构与表约束
  10. ZooKeeper 分布式共享锁的实现
  11. 小甲鱼OD学习第6讲
  12. 弹出层之2:JQuery.BlockUI
  13. npm 安装卸载模块
  14. JAVA中字符串操作几种方式对比
  15. kali 解决Metasploit拿到shell后显示中文乱码问题
  16. 【Java虚拟机】浅谈Java虚拟机
  17. 746. Min Cost Climbing Stairs
  18. Shiro的使用
  19. ImageView的android:scaleType各属性含义(zz)
  20. tomcat服务器开启gzip功能的方法

热门文章

  1. 如何处理Docker的错误消息request canceled:Docker代理问题
  2. 10g集群启动顺序
  3. TCP socket如何判断连接断开
  4. docker 新手入门 (阿里镜像仓库的使用)
  5. 细说PHP-5.3.4变量的引用赋值
  6. python之路——函数进阶
  7. 光猫&amp;路由器网络配置
  8. 调试bug方法总结
  9. node.js从入门到放弃(二)
  10. 02numpy