no.. each ans[s] is stored before returning.. so there is no recalculation
of any substring
On Sun, Sep 18, 2011 at 4:12 AM, Marcelo Amorim Menegali
mmeneg...@gmail.com wrote:
*ans[s]=find(s+1,len-1);*
if(s[0]'3's[1]'7')
*ans[s] = ans[s]+find(s+2,len-2);*
--
You
i'm trying out this problem www.spoj.pl/problems/ACODE
i'm getting TLE.. I donno y my recursion leads to tle
#includeiostream
#includemap
#includestdio.h
#includestring.h
using namespace std;
mapstring, long long ans;
mapstring, bool flags;
long long find(char *s, int len){
if(flags[s])
I think you're getting TLE because your solution calculate the same stuff
over and over again.
Look at this part:
else{
*ans[s]=find(s+1,len-1);*
if(s[0]'3's[1]'7')
*ans[s] = ans[s]+find(s+2,len-2);*
}
Calculating find(s+1,len-1) imply that
given a string find the number of distinct substrings of the string.
ex:
input-
output- 4(a, aa, aaa, )
input-abcd
output-10(a, b, c, d, ab, bc, cd, abc, bcd, abcd)
--
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this
You r given a large string of characters lets call it Sbig. Then there
is a small set of characters lets call it Ssmall. You have to find
smallest substring of Sbig which contains all characters in Ssmall.
For example you are given Sbig = hello what are you doing
Ssmall= eo
answer is ello
24
--
http://codepad.org/NDAeIpxR
http://codepad.org/NDAeIpxRHere is code for it
On Sat, Jun 26, 2010 at 9:54 PM, Anand anandut2...@gmail.com wrote:
you can use Longest common subsequence algorithm to solve it.
On Sat, Jun 26, 2010 at 4:04 PM, amit amitjaspal...@gmail.com wrote:
You r given a