UVA - 620 Cellular Structure
来源:互联网 发布:php 图文直播系统 编辑:程序博客网 时间:2024/06/11 21:00
题意:唉,只要理解题意就会很简单了,看了别人的题解明白了,
思路:所谓的上下文无关文法就是给定几个算术表达式,然后通过一些相关的变化,可以推出另一个表达式。
回到题目,由图片可以知道, O = BOA,我们把BOA中的O看做一个表达式,这里O可以看做O = A | OAB | BOA,由此可知:
OAB推出的子串 OABAB, OABABAB,....AB的最后两位一定是AB。①
同理BOA推出的子串 BBOAA, BBBOAAA等,这样的子串特定是:首字母为B,尾字母为A。②
由1、2可以知道,他们的子串的长度一定是奇数,如果为偶数,那么字符串的类型一定是Mutant。
而O = A,则是 simple stage,同样为奇数。
#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int MAXN = 1005;char arr[MAXN]; char st[4][20] = {"SIMPLE", "FULLY-GROWN", "MUTAGENIC", "MUTANT"}; int dp(int x,int y){ if (y - x == 1) return arr[x] = 'A' ? 0 : 3; if (arr[y-1] == 'B' && arr[y-2] == 'A') return dp(x,y-2) == 3 ? 3 : 1; if (arr[x] == 'B' && arr[y-1] == 'A') return dp(x+1,y-1) == 3 ? 3 : 2; return 3; }int main(){ int n,ans; scanf("%d",&n); for (int i = 0; i < n; i++){ scanf("%s",arr); int len = strlen(arr); if (len % 2 == 0) ans = 3; else { ans = dp(0,len); } printf("%s\n",st[ans]); } return 0;}
- uva 620 Cellular Structure
- UVA 620 Cellular Structure
- UVa 620 - Cellular Structure
- uva 620 - Cellular Structure
- UVa 620 - Cellular Structure
- Uva-620-Cellular Structure
- uva 620 Cellular Structure
- uva 620 - Cellular Structure
- UVA - 620 Cellular Structure
- UVa:620 Cellular Structure
- uva 620 Cellular Structure
- UVA - 620 Cellular Structure
- UVA 620 Cellular Structure
- UVA 620 - Cellular Structure
- UVA - 620 Cellular Structure
- UVa 620 Cellular Structure
- UVA 620 Cellular Structure
- UVa 620 - Cellular Structure
- 假如生活欺骗了你
- 理解WebKit和Chromium: Chromium插件和扩展基础
- C# 利用代理 (proxy) 爬网
- UVa 488 Triangle Wave (water ver.)
- Android广播机制(两种注册方法)与 中断广播
- UVA - 620 Cellular Structure
- 如何正确为函数参数中的指针动态分配内存
- 理解WebKit和Chromium: 网页渲染的基本过程
- JDBC连接数据库_DBConnTest.java_20130913
- C++类型安全
- C#读取纯真IP数据库
- Git 中文教程
- 理解WebKit和Chromium: Web应用和Web运行环境
- shell script 学习之 bash设定文件分析