アットウィキロゴ

jhgbvcxz

class makeword{

double[] pr=new double[101];  
int strlong,slong,tlong,wordnumber;
String[][] ph=new String[500][11];
String[] phx=new String[500];
String[] word=new String[500];
int s,sx,t,tx,sxs,txs;
int[] dbnumber=new int[1002];
String[][] db=new String[1001][500];
double[][] v=new double[500][11];
int[][] gototx=new int[500][11];
int z,xx;
double v1,maxv;

void makedata(String str){

makepr();

strlong=str.length();

for(s=1;s<strlong+1;s++){
slong=s;
if(slong>10)slong=10;
for(sx=1;sx<slong+1;sx++){
ph[s][sx]=str.substring(s-sx,s);
}
}

for(s=1;s<11;s++){
v[s][s]=pr[s]*g(ph[s][s]);
}

v[2][1]=pr[1]*f(ph[1][1],ph[2][1])*v[1][1];
gototx[2][1]=1;

for(s=3;s<strlong+1;s++){
slong=s-1;
if(slong>10)slong=10;
for(sx=1;sx<slong+1;sx++){
t=s-sx;
tlong=t-1;
if(tlong>10)tlong=10;
maxv=-999;
txs=0;
for (tx=1;tx<tlong+1;tx++){
v1=pr[sx]*f(ph[t][tx],ph[s][sx])*v[t][tx];
if(v1>maxv)txs=tx;
if(v1>maxv)maxv=v1;
}
v[s][sx]=maxv;
gototx[s][sx]=txs;
}
}


s=strlong;
maxv=-999;
sxs=0;
for(sx=1;sx<11;sx++){
if(v[s][sx]>maxv)sxs=sx;
if(v[s][sx]>maxv)maxv=v[s][sx];
}

sx=sxs;
z=s-sx;
xx=0;
while(z>0){
xx=xx+1;
phx[xx]=ph[s][sx];
t=s-sx;
tx=gototx[s][sx];
s=t;
sx=tx;
z=s-sx;
}
xx=xx+1;
phx[xx]=ph[s][sx];

wordnumber=xx;

for(s=1;s<wordnumber+1;s++){
word[s]=phx[wordnumber+1-s];
}



}
double g(String ph1){
int t1,m1,m2;
String strx;
double px;
px=0.001;
m1=0;
for(t1=1;t1<1001;t1++){
if(dbnumber[t1]>0)m1=m1+1;
}

m2=0;
for(t1=1;t1<1001;t1++){
strx="";
if(dbnumber[t1]>0)strx=db[t1][1];
if(strx.equals(ph1))m2=m2+1;
}

if(m1>0)px=(double)m2/m1;
if(px<0.001)px=0.001;
return px;
}


double f(String ph1,String ph2){
int t1,t2,m1,m2,h;
String strx;
double px;
px=0.001;
m1=0;
for(t1=1;t1<1001;t1++){
for(t2=1;t2<dbnumber[t1];t2++){
if(db[t1][t2].equals(ph1))m1=m1+1;
}
}
m2=0;
for(t1=1;t1<1001;t1++){
for(t2=1;t2<dbnumber[t1];t2++){
h=0;
if(db[t1][t2].equals(ph1))h=h+1;
if(db[t1][t2].equals(ph1))h=h+1;
if(h==2)m2=m2+1;
}
}
if(m1>0)px=(double)m2/m1;
if(px<0.001)px=0.001;
return px;
}
void makepr(){
double p1,c1,c2;
int k;
p1=0.05;
c1=0;
for(k=1;k<101;k++){
c1=c1+Math.pow(1-p1,k)*p1;
}  
for(k=1;k<101;k++){
pr[k]=Math.pow(1-p1,k)*p1/c1;
}

}

}
最終更新:2011年05月29日 14:57