Link : https://www.spoj.pl/problems/ACODE/
25114
BEAN’, ‘BEAAD’, ‘YAAD’, ‘YAN’, ‘YKD’ ‘BEKD’.
How many different decodings?”
My soln , but i get TLE.Please help.
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
char * head;
int result[5001];
int count(char * a ,int size)
{
if(result[a-head]!=0){
return result[a-head];
}
if(size==1)
return 1;
else if (size==2)
{
if(a[0]>'2')
return 1;
else
return 2;
}
else
{
int temp = count(a+1,size-1);
if(a[0]>'2' || (a[0]=='2' && a[1]>'6'))
{
result[a-head] = temp ;
return temp;
}
else
{
int r = temp+count(a+2,size-2);
result[a-head] = r;
return r;
}
}
}
int main()
{
char ch;
cin>>ch;
while(ch!='0')
{
char input[5001];
int index=0;
while(ch!='\n')
{
//input.push_back(ch-'0');
input[index]=ch;
index++;
scanf("%c",&ch);
}
cin>>ch;
head = input ;
for(int i=0;i<=5000;i++)
result[i]=0;
cout<<count(input,index)<<endl;
}
return 0;
}
--
regards,
chinna.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.