アットウィキロゴ

はば

class pro{

double[] pos=new double[101];
String str;
int s,sx,sxs,m,ms,slong,tlong,strlong;
int dicnumber;
String[][] ph=new String[500][11];
int[][] nph=new int[500][11];
String[] dic=new String[1000];
double[] fp=new double[1000];
double[] mp=new double[1000];
double[][] v=new double[500][11];
int[][] gototx=new int[500][11];
int[] mp1=new int[1000];
int[] mp2=new int[1000];
String[] word=new String[500];
int[] nword=new int[500];
int mpnumber,wordnumber;
int t,tx,txs,h;
int[] num=new int[1000];
double p1;
double[] p=new double[1000];
double v1,maxv;
int tr;

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

pro(){

makepos();

mpnumber=0;
dicnumber=0;
fp[0]=1;
mp[0]=1;
p[0]=1;

str="実用化につながるブレークスルーとしては、1970年代に発声時間長の伸縮を動的計画法";
strlong=str.length();

System.out.println(strlong);

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

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

m=mk(nph[1][1],nph[2][1]);
v[2][1]=pos[1]*mp[m]+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++){
m=mk(nph[t][tx],nph[s][sx]);
v1=sx*pos[sx]*mp[m]+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];
}

makeword(sxs);

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=0;s<dicnumber+1;s++){
num[s]=0;
}

for(s=1;s<wordnumber;s++){
sx=nword[s];
num[sx]=num[sx]+1;
}

for(s=0;s<dicnumber+1;s++){
p1=(double)num[s]/(wordnumber-1);
p[s]=0.95*p[s]+0.05*p1;
}


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

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

for(s=1;s<wordnumber;s++){
sx=mk(nword[s],nword[s+1]);
if(sx==0)mpnumber=mpnumber+1;
if(sx==0)mp1[mpnumber]=nword[s];
if(sx==0)mp2[mpnumber]=nword[s+1];
if(sx==0)num[mpnumber]=1;
if(sx>0)num[sx]=num[sx]+1;
}

for(s=0;s<mpnumber+1;s++){
if(wordnumber>1)p1=(double)num[s]/(wordnumber-1);
if(wordnumber>1)mp[s]=0.95*p[s]+0.05*p1;
}


System.out.println(mpnumber);

}




}

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];
}

}



void makeword(int sxs){

int s,sx,t,tx;
int[] op1=new int[500];
int[] op2=new int[500];  
int z,c,h;
sx=sxs;
s=strlong;  
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+1];
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];
}

}

int mk(int sx1,int sx2){
int h,sx,sxs;
sxs=0;
for(sx=1;sx<mpnumber+1;sx++){
h=0;
if(mp1[sx]==sx1)h=h+1;
if(mp2[sx]==sx2)h=h+1;
if(h==2)sxs=sx;
}
return sxs;
}


}
最終更新:2011年05月30日 18:20