class pro{
String str;
int s,sx,t,tx,txs,sxs,strlong,slong,tlong;
String[][] ph=new String[500][11];
String[] phx=new String[500];
double[][] v=new double[500][11];
int[] dbnumber=new int[1001];
String[][] db=new String[1001][500];
int[][] gototx=new int[500][11];
String[] word=new String[500];
double[] pos=new double[101];
double v1,maxv;
int xx,z,wordnumber;
int page,tr;
public static void main(String args[]){
pro test=new pro();
}
pro(){
makepos();
page=0;
for(tr=1;tr<100;tr++){
str="北海道占冠(しむかっぷ)村のJR石勝線で上り特急列車";
strlong=str.length();
System.out.println(strlong);
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]=pos[s]*s*g(ph[s][s]);
}
v[2][1]=pos[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;
if(tlong>10)tlong=10;
maxv=-999;
txs=0;
for (tx=1;tx<tlong+1;tx++){
v1=pos[sx]*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];
System.out.println(word[s]);
}
page=page+1;
if(page>1000)page=1;
dbnumber[page]=wordnumber;
for(s=1;s<wordnumber+1;s++){
db[page][s]=word[s];
}
}
}
void makepos(){
double lam,x1,x2;
double[] cx=new double[101];
int k;
lam=4.8;
x1=1-lam;
cx[1]=1;
cx[2]=1;
for(k=3;k<101;k++){
cx[k]=(k-1)*cx[k-1];
}
for(k=1;k<101;k++){
x2=Math.pow(lam-1,k);
pos[k]=x2*Math.exp(x1)/cx[k];
}
}
double f(String ph1,String ph2){
int t1,t2,m1,m2,m3,h;
String strx;
double px,qx,n1;
px=0.01;
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;
}
}
m3=0;
for(t1=1;t1<1001;t1++){
if(dbnumber[t1]>0)m3=m3+1;
}
qx=0;
if(m1>0)qx=(double)m2/m1;
n1=(double)m3/1000;
px=(1-n1)*px+n1*qx;
return px;
}
double g(String ph1){
int t1,m1,m2;
String strx;
double px,qx;
double n1;
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;
}
qx=0;
if(m1>0)qx=(double)m2/m1;
n1=(double)m1/1000;
px=(1-n1)*px+n1*qx;
return px;
}
}
最終更新:2011年05月30日 08:12