import java.util.Arrays;
import java.util.Comparator;
import org.junit.Test;
public class solution {
@Test
public void testFunc(){
int res = search(22);
System.out.println("res: "+res);
}
//把数字翻译成字符串
/*
* 实现过程:
* f(i)=f(i+1)+g(i,i+1)*f(i+2)
*/
private int[] memo;
public int search(int num1){
String num = num1+"";
memo = new int[num.length()];
Arrays.fill(memo, -1);
memo[num.length()-1]=1;
return searchNum(num,0);
}
public int searchNum(String num, int index){
if (index+1==num.length()) {
return memo[index];
}
if (memo[index]==-1) {
String string=num.substring(index,index+2);
Integer tempNum = Integer.valueOf(string);
int res1=0,res2=0;
res1=searchNum(num, index+1);
if (tempNum<=25 && index+2==num.length()) {
res2=1;
}
if (tempNum<=25 && index+2<num.length()) {
res2=searchNum(num, index+2);
}
memo[index]=res1+res2;
return res1+res2;
}
return memo[index];
}
}