class x{
String str;
int strlong;
int dicnumber;
double[] p=new double[1000];
String[] dic=new String[1000];
String ph;
int t,sx,sxs,nx,nxs,n;
double p1;
double[][] v=new double[500][6];
double v1,maxv;
public static void main(String args[]){
x test=new x();
}
x(){
dicnumber=0;
p[0]=0.001;
str="猫はかわいい";
strlong=str.length();
ph=str.substring(0,1);
sxs=0;
for(sx=1;sx<dicnumber+1;sx++){
if(ph.equals(dic[sx]))sxs=sx;
}
p1=p[sxs];
v[0][0]=p1;
v[0][1]=0;
for(t=1;t<strlong;t++){
nxs=t;
if(nxs>4)nxs=4;
maxv=-999;
for(nx=0;nx<nxs+1;nx++){
ph=str.substring(t-nx,t+1);
sxs=0;
for(sx=1;sx<dicnumber+1;sx++){
if(ph.equals(dic[sx]))sxs=sx;
}
p1=p[sxs];
v1=p1+v[t-1][nx];
if(v1>maxv)maxv=v1;
}
v[t][0]=maxv;
nxs=t;
if(nxs>4)nxs=4;
for(nx=0;nx<nxs+1;nx++){
v[t][nx+1]=v[t-1][nx];
}
}
t=strlong;
nxs=t;
if(nxs>4)nxs=4;
maxv=-999;
for(nx=0;nx<nxs+1;nx++){
ph=str.substring(t-nx,strlong);
sxs=0;
for(sx=1;sx<dicnumber+1;sx++){
if(ph.equals(dic[sx]))sxs=sx;
}
p1=p[sxs];
v1=p1+v[t-1][nx];
if(v1>maxv)maxv=v1;
}
System.out.println(maxv);
}
}
最終更新:2011年05月26日 08:15