class pro{
String str;
int strlong,slong,tlong;
int s,sx,t,tx,txs,sxs;
String[][] ph=new String[500][11];
double[][] v=new double[500][11];
int[] dbnumber=new int[1001];
String[][] db=new String[1001][500];
int[][] gototx=new int[500][11];
String[] phx=new String[500];
String[] word=new String[500];
int wordnumber;
double v1,maxv;
int z,xx;
public static void main(String args[]){
pro test=new pro();
}
pro(){
str="気象庁によると、四国沖を北東方向に進んでいる台風2号";
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]=s*g(ph[s][s]);
}
v[2][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=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]);
}
}
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;
}
}
最終更新:2011年05月29日 18:21