アットウィキロゴ

nhjkl;;:

class pro{

String str;
int s,sx,t,tx,txs,strlong,slong,tlong;
String[][] ph=new String[500][11];
String[] dic=new String[500];
String[] word=new String[500];
int[] nword=new int[500];
int[][] nph=new int[500][11];
int[] p1=new int[500];
int[] p2=new int[500];
int[] op=new int[500];
int[] num=new int[500];
int mx,mxs;
int dicnumber,pnumber,wordnumber;
int sx1,sx2,sxs;
double[][] v=new double[500][11];
int[][] gototx=new int[500][11];
double[] p=new double[500];
double[] px=new double[500];
double[] q=new double[500];
int[] op1=new int[500];
int[] op2=new int[500];
int h;
double v1,maxv;
int z,c,tr;

public static void main(String args[]){
pro test=new pro();
}

pro(){

dicnumber=0;
pnumber=0;
p[0]=1;
q[0]=1;

str="東日本大震災による地盤沈下で道路など";
strlong=str.length();

for(tr=1;tr<100;tr++){

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<strlong+1;s++){
slong=s;
if(slong>10)slong=10;
for(sx=1;sx<slong+1;sx++){
mxs=0;
for(mx=1;mx<dicnumber+1;mx++){
if(ph[s][sx].equals(dic[mx]))mxs=mx;
}
nph[s][sx]=mxs;
}
}


slong=strlong;
if(slong>10)slong=10;
for(s=1;s<slong+1;s++){
sx=nph[s][s];
v[s][s]=q[sx];
}

sx1=nph[1][1];
sx2=nph[2][1];

sxs=0;
for(sx=1;sx<pnumber+1;sx++){
h=0;
if(p1[sx]==sx1)h=h+1;
if(p2[sx]==sx2)h=h+1;
if(h==2)sxs=sx;
}

v[2][1]=q[sxs]+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++){
mxs=0;
for(mx=1;mx<pnumber+1;mx++){
h=0;
if(p1[mx]==nph[t][tx])h=h+1;
if(p2[mx]==nph[s][sx])h=h+1;
if(h==2)mxs=mx;
}
v1=p[mxs]+v[t][tx];
if(v1>maxv)txs=tx;  
if(v1>maxv)maxv=v1;
}
gototx[s][sx]=txs;
v[s][sx]=maxv;  
}
}

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


s=strlong;
sx=sxs;
z=s-sx;
op1[1]=s;
op2[1]=sx;
c=1;
while(z>1){
t=s-sx;
tx=gototx[s][sx];
s=t;
sx=tx;
c=c+1;
op1[c]=s;
op2[c]=sx;
z=s-sx;
}

h=0;
if(op1[c]>op2[c])h=100;
if(h>50)op1[c+1]=op1[c]-op2[c];
if(h>50)op2[c+1]=op1[c]-op2[c];
if(h>50)c=c+1;

wordnumber=c;
for(c=1;c<wordnumber+1;c++){
s=op1[c];
sx=op2[c];
word[wordnumber+1-c]=ph[s][sx];
}


for(s=1;s<wordnumber+1;s++){
sxs=0;
for(sx=1;sx<dicnumber+1;sx++){
if(word[s].equals(dic[sx]))sxs=sx;
}
if(sxs==0)dicnumber=dicnumber+1;
if(sxs==0)dic[dicnumber]=word[s];
if(sxs==0)nword[s]=dicnumber;
if(sxs>0)nword[s]=sxs;
}

for(s=1;s<pnumber+1;s++){
num[s]=0;
}

for(s=1;s<wordnumber;s++){
sx1=nword[s];
sx2=nword[s+1];
sx=0;
for(sx=1;sx<pnumber+1;sx++){
h=0;
if(sx1==p1[sx])h=h+1;
if(sx2==p2[sx])h=h+1;
if(h==2)sxs=sx;
}
if(sxs==0)pnumber=pnumber+1;
if(sxs==0)p1[pnumber]=sx1;
if(sxs==0)p2[pnumber]=sx2;
if(sxs==0)num[pnumber]=1;
if(sxs>0)num[sxs]=num[sxs]+1;
}

for(s=1;s<pnumber+1;s++){
px[s]=(double)num[s]/(wordnumber-1);
}

for(s=0;s<pnumber+1;s++){
p[s]=0.95*p[s]+0.05*px[s];
}

for(s=0;s<dicnumber+1;s++){
h=0;
if(nword[1]==s)h=100;
if(h>50)q[s]=0.95*q[s]+0.05;
if(h<50)q[s]=0.95*q[s];
}

System.out.println(dicnumber);

}

System.out.println(strlong);






}
}
最終更新:2011年05月30日 14:22