In Bioinformatics, a DNA sequence is made up of a
combination of 4 characters, namely “A,C,G,T”. A
subsequence of a given sequence of characters a0, a1, …an-
1, is any subset of the characters taken in order, of the
form ai0 , ai1 ,…..aik-1 where 0 ≤ i0 <i1….< ik-1 ≤ n-1.
For example in the sequence “A,C,G,T,G,T,C,A,A,A,A,T,C,G”,
we can have subsequences “A,G,T”, “A,C,A,A” and many more.
A subsequence is palindromic if it is the same whether read
left to right or right to left. For instance, the
sequence “A,C,G,T,G,T,C,A,A,A,A,T,C,G”, has many
palindromic subsequences, including “A,C,G,C,A”
and “A,A,A,A” (on the other hand, the subsequence “A,C,T”
is not palindromic). Devise an algorithm (using dynamic
programming) that takes a sequence of characters X[0 … n-1]
from the alphabet set (A,C,G,T) and returns the (length of
the) longest palindromic subsequence. Implement the
algorithm in an appropriate language.
Answer / pragnesh
import java.io.*;
import java.util.*;
public class p3{
public static void main(String[] args) throws
FileNotFoundException{
Scanner inFile = new Scanner(new FileReader("words.txt"));
String s;
String temp, tempRev="";
while(inFile.hasNext()){
s=inFile.nextLine();
temp=s;
temp = temp.replace("?","");
temp = temp.replace(".","");
temp = temp.replace(",","");
temp = temp.replace(":","");
temp = temp.replace("\"","");
temp = temp.replace(" ","");
for(int x=temp.length()-1;x>=0;x--)
tempRev = tempRev + temp.charAt(x);
if(temp.equalsIgnoreCase(tempRev))
System.out.println(s + " is a palindrome");
else
System.out.println(s + " is not a palindrome");
tempRev="";
}
inFile.close();
}
}
maybe you could adapt that to c++
| Is This Answer Correct ? | 0 Yes | 2 No |
Which method protects back button to retrieve old value from previous page in Struts.
What are the Advantages of HashMap over Vector?
we create a pf with 3 fields.2 is defined as keyfields.we lock it with alcobj command.how we find out whether the file is locked or not?is it dspfd??/
When we have two versions of the dot net installed how does the compiler know which version of DLL it has to select to an application.
what is microprocessor?
how to display xisheet in list box in c# .net
What is the worst case of AVL tree?
what is best way to create a Thread class & why?
how will you code the subfile which is in editing mode (multiple case subfile)?
what is meant by trigger?
what is the difference between an application and service??? i mean service which runs as in services.msc.
I am looking for selenium RC online Training in chennai. can any one tell me the best institute