アットウィキロゴ

他部門x

package den;
 
 
public class pro {
 
double[][] p=new double[3][3];
int[] price=new int[1000];
int[] y=new int[1000]; 
int[] k=new int[1000]; 
int s,number;
double[][] v=new double[101][11];
int[][] gotok=new int[101][11];
int[] op=new int[101];
 
    public static void main(String[] args) {
        pro t=new pro();
    }
    pro(){
 
 
        p[1][1]=0.9;
        p[1][2]=0.1;
        p[2][1]=0.1;
        p[2][2]=0.9;
 
        number=100;
 
        for(s=1;s<number+1;s++){
            price[s]=1;
        if(Math.random()>0.5)price[s]=2;    
        }
 
 
        for(s=1;s<number+1;s++){
        y[s]=5;    
        }
 
        int t,h;
        double p1;
        for(s=1;s<11;s++){
        v[1][s]=u(1,s);
 
 
        }
 
        int sx,sxs;
        double v1,e1,maxv;
 
        for(t=2;t<number+1;t++){
        for(s=1;s<11;s++){
        double u1=u(t,s);
        maxv=-999;
        sxs=0;
        for(sx=1;sx<11;sx++){
        v1=u1+v[t-1][sx];    
        e1=(s-sx)*(s-sx);
        if(e1>1)v1=-999;
        if(v1>maxv)sxs=sx;
        if(v1>maxv)maxv=v1;
        }
        gotok[t][s]=sxs;
        v[t][s]=maxv;
        }    
        }    
 
        maxv=-999;
        sx=0;
         for(s=1;s<11;s++){
          if(v[number][s]>maxv)sx=s;
         if(v[number][s]>maxv)maxv=v[number][s];
 
         System.out.println(s+","+v[number][s]);
         }
        op[number]=sx;
         for(s=1;s<number;s++){
         sx=op[number-s+1];
         op[number-s]=gotok[number-s+1][sx];
         }
 
 
          for(s=1;s<number+1;s++){
          System.out.println(op[s]);
          }
 
 
 
 
 
 
        }
 
 
 
 
 
 
 
 
    double u(int t,int k1){
 
        double p1,u1;
        int h;
 
        p1=0.5;
        h=0;
        if(price[t]==1)h=h+1;
        if(y[t]>k1-1)h=h+1;    
        if(h==2)p1=p[1][1];
        h=0;
        if(price[t]==2)h=h+1;
        if(y[t]>k1-1)h=h+1;    
        if(h==2)p1=p[1][2];
        h=0;
        if(price[t]==1)h=h+1;
        if(y[t]<k1)h=h+1;    
        if(h==2)p1=p[2][1];
        h=0;
        if(price[t]==2)h=h+1;
        if(y[t]<k1)h=h+1;    
        if(h==2)p1=p[2][2];
 
        u1=Math.log(p1);
 
        return u1;
}
 
 
 
}
 
最終更新:2015年07月30日 13:26