Cellular Structure+uva+简单区间dp
2014-09-27 09:15
176 查看
Cellular Structure
Description![](http://uva.onlinejudge.org/components/com_onlinejudge/images/button_pdf.png)
A chain of connected cells of two types A and B composes a cellular structure of some microorganisms of species APUDOTDLS.If no mutation had happened during growth of an organism, its cellular chain would take one of the following forms:
Time Limit: 3000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
![](http://uva.onlinejudge.org/components/com_onlinejudge/images/button_pdf.png)
Cellular Structure |
Sample notation O = OA means that if we added to chain of a healthy organism a cell A from the right hand side, we would end up also with a chain of a healthy organism. It would grow by one cell A.A laboratory researches a cluster of these organisms. Your task is to write a program which could find out a current stage of growth and health of an organism, given its cellular chain sequence.simple stage O = A
fully-grown stage O = OAB
mutagenic stage O = BOA
Input
A integer n being a number of cellular chains to test, and then n consecutivelines containing chains of tested organisms.Output
For each tested chain give (in separate lines) proper answers:SIMPLE for simple stage FULLY-GROWN for fully-grown stage MUTAGENIC for mutagenic stage MUTANT any other (in case of mutated organisms)If an organism were in two stages of growth at the same time the first option from the list above should be given as an answer.
Sample Input
4 A AAB BAAB BAABA
Sample Output
SIMPLE FULLY-GROWN MUTANT MUTAGENIC
解决方案:开始理解题目有点困难,后面才懂。O=A 即只有A细胞的一个organism,O=OAB 即以AB细胞结尾的organism,O=BOA 即以B开头A结尾的organism,O代表organism。dp[i][j][k],代表i到j区间,k代表那几种organism。所以可以从下往上更新:
先是:
1)dp[i][i][1]=1 当str[i]=='A'
2)dp[i][j][2]=dp[i][j-2][1]|dp[i][j-2][2]|dp[i][j-2][3] 当str[j-1]=='A'&&str[j]=='B';
3)dp[i][j][3]=dp[i+1][j-1][1]|dp[i+1][j-1][2]|dp[i+1][j-1][3] 当str[i]=='A'&&str[j]=='B';
code:#include <iostream>#include<cstring>#include<string>#include<cstdio>using namespace std;char text[1000];int dp[1000][1000][4];int main(){int t;scanf("%d",&t);while(t--){scanf("%s",text+1);memset(dp,0,sizeof(dp));int len=strlen(text+1);for(int i=1; i<=len; i++){if(text[i]=='A') dp[i][i][1]=1;}for(int i=2; i<=len; i++){for(int j=1; j+i<=len; j++){if(text[j+i-1]=='A'&&text[j+i]=='B'){dp[j][j+i][2]=dp[j][j+i-2][1]|dp[j][j+i-2][3]|dp[j][j+i-2][2];}if(text[j]=='B'&&text[j+i]=='A'){dp[j][j+i][3]=dp[j+1][j+i-1][1]|dp[j+1][j+i-1][2]|dp[j+1][j+i-1][3];}}}if(dp[1][len][1]){printf("SIMPLE\n");}else if(dp[1][len][2]){printf("FULLY-GROWN\n");}else if(dp[1][len][3]){printf("MUTAGENIC\n");}else{printf("MUTANT\n");}}return 0;}
相关文章推荐
- Optimal Array Multiplication Sequence+uva+简单区间dp
- UVA-1626 Brackets sequence (简单区间DP)
- UVA 10453 Make Palindrome(区间简单DP)
- uva 10003 Cutting Sticks 简单区间dp
- uva 1169 Robotruck(简单区间dp)
- UVa 607 Scheduling Lectures(简单DP)
- UVa 11258 String Partition(简单DP)
- UVa 590 Always on the run(简单链式DP)
- UVa 10739 String to Palindrome(经典回文串区间DP)
- UVa 562 Dividing coins(简单DP)
- UVa 10003 - Cutting Sticks 区间dp
- UVa 10891 Game of Sum(经典博弈区间DP)
- UVa 116 Unidirectional TSP(简单旅行商DP)
- uva10003 - Cutting Sticks(DP,区间)
- 简单树形dp uvaLive 4472
- uva 1424 简单DP
- uva_10891 - Game of Sum( 博弈区间DP )
- UVa 825 Walking on the Safe Side(简单DP)
- UVa 10003 Cutting Sticks(区间DP)
- UVa 10617 Again Palindrome(经典回文串区间DP)