tg9963
BAN USERThe above solution doesn't give the desired output. check the one below.
void getNonOverLappingUtil(string prevPrefix,string s, map<string,bool> &stringMap){
long strLen = s.length();
for(int indx=1; indx<=strLen; indx++){
string commonPrefix = s.substr(0,indx);
commonPrefix = "("+commonPrefix+")";
string leftOutSuffix = s.substr(indx,strLen);
getNonOverLappingUtil(prevPrefix + commonPrefix,leftOutSuffix,stringMap);
if(leftOutSuffix.length() > 0){
leftOutSuffix = "("+leftOutSuffix+")";
}
if (stringMap.find(prevPrefix + commonPrefix + leftOutSuffix) == stringMap.end()) {
stringMap[prevPrefix + commonPrefix + leftOutSuffix] = true;
}
}
}
void printNonOverLapping(string s){
map<string,bool> stringMap;
getNonOverLappingUtil("",s,stringMap);
map<string,bool>::iterator it;
for(it = stringMap.begin();it!=stringMap.end();it++){
cout<<(*it).first<<endl;
}
}
import java.io.*;
class fib
{
public static void main(String args[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
int n=Integer.parseInt(str);
n=fib(n);
System.out.println("Fibb is "+n);
}
public static int fib(int n){
if(n==1 | n==0)return 1;
else return fib(n-1)+fib(n-2);
}}
- tg9963 January 11, 2014
Create a trie with all the words in the dictionary. Sort all the given characters. Traverse the trie to find the minimum length word.
- tg9963 July 02, 2016