public class tax24{
public static void main(String[] args) {
int j,s,n,n1,n2,n3,m,z,mx;
double th[]=new double[101];
double c[]=new double[11];
double y[]=new double[11];
double ux[][][][]=new double[11][3][3][3];
double b[][][][]=new double[11][3][3][3];
int endbx[][]=new int[3][3];
int fastbx[][]=new int[3][3];
int bx[][][][]=new int[11][3][3][3];
double fastu[][]=new double[3][3];
double fastb[][]=new double[3][3];
double endu[][]=new double[3][3];
int endm[][]=new int[3][3];
double endb[][]=new double[3][3];
double v[][][][]=new double[11][3][3][21];
int goton[][][][]=new int[11][3][3][21];
int gotom[][][][]=new int[11][3][3][21];
double fastv[][][]=new double[3][3][21];
double endv[][]=new double[3][3];
int gr[]=new int[101];
double tl,tr,w1,maxw,maxtl,maxtr,maxu,sumu,maxv;
double c1,l1,c2,l2,c3,l3,u1,u2,u3,v1,y1;
double h,b0,b1;
double maxc,maxl,supv;
double dc,dy;
int op[]=new int[11];
int ns1,ns2,mxs,nxs,ms;
int t;
for (s=1;s<101;s++){
th[s]=0.02*s;
}
for (n=0; n<11;n++){
y[n]=0.1*n;
}
maxtl=0.1;
maxtr=0;
maxw=-999;
for (j=10;j<50;j++){
tl=0.01*j;
tr=trs(tl,y,th);
for (n=0; n<11;n++){
c[n]=(1-tl)*y[n]+tr;
}
w1=wel(c,y,th);
if (w1>maxw)maxtl=tl;
if (w1>maxw)maxtr=tr;
if (w1>maxw)maxw=w1;
}
tl=maxtl;
tr=maxtr;
for (n=0; n<11;n++){
c[n]=(1-tl)*y[n]+tr;
}
for (s=1; s<101;s++){
gr[s]=prefer(s,c,y,th);
}
h=0.001;
t=0;
supv=-999;
while (t<1000){
for (n=1;n<10;n++){
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
for (n3=-1; n3<2;n3++){
ux[n][n1+1][n2+1][n3+1]=seeku(n,n1,n2,n3,gr,c,y,th,h);
}
}
}
}
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
fastu[n1+1][n2+1]=seekfastu(n1,n2,gr,c,y,th,h);
}
}
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
endu[n1+1][n2+1]=seekendu(n1,n2,gr,c,y,th,h);
}
}
for (n=1;n<10;n++){
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
for (n3=-1; n3<2;n3++){
b[n][n1+1][n2+1][n3+1]=seekb(n,n1,n2,n3,gr,c,y,th,h);
}
}
}
}
for (n=1;n<10;n++){
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
for (n3=-1; n3<2;n3++){
b0=b[n][1][1][1];
b1=b[n][n1+1][n2+1][n3+1];
bx[n][n1+1][n2+1][n3+1]=(int)((b1-b0)/h);
}
}
}
}
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
endb[n1+1][n2+1]=seekendb(n1,n2,gr,c,y,th,h);
}
}
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
b1=endb[n1+1][n2+1];
b0=endb[1][1];
endbx[n1+1][n2+1]=(int)((b1-b0)/h);
}
}
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
fastb[n1+1][n2+1]=seekfastb(n1,n2,gr,c,y,th,h);
}
}
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
b1=fastb[n1+1][n2+1];
b0=fastb[1][1];
fastbx[n1+1][n2+1]=(int)((b1-b0)/h);
}
}
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
for (m=-10; m<11;m++){
fastv[n1+1][n2+1][m+10]=-999;
}
}
}
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
m=fastbx[n1+1][n2+1];
u1=fastu[n1+1][n2+1];
z=0;
if (m>10)z=100;
if (m<-10)z=100;
if (z>50)m=0;
if (z>50)u1=-999;
fastv[n1+1][n2+1][m+10]=u1;
}
}
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
for (m=-10; m<11;m++){
maxv=-999;
mxs=0;
nxs=0;
for (n3=-1; n3<2;n3++){
u1=ux[1][n1+1][n2+1][n3+1];
mx=m-bx[2][n1+1][n2+1][n3+1];
z=0;
if (mx>10)z=100;
if (mx<-10)z=100;
if (z>50)mx=0;
v1=u1+fastv[n2+1][n3+1][mx+10];
if (z>50)v1=-999;
if (v1>maxv)nxs=n3;
if (v1>maxv)mxs=mx;
if (v1>maxv)maxv=v1;
}
goton[1][n1+1][n2+1][m+10]=nxs;
gotom[1][n1+1][n2+1][m+10]=mxs;
v[1][n1+1][n2+1][m+10]=maxv;
}
}
}
for (n=2;n<10;n++){
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
for (m=-10; m<11;m++){
maxv=-999;
mxs=0;
nxs=0;
for (n3=-1; n3<2;n3++){
u1=ux[n][n1+1][n2+1][n3+1];
mx=m-bx[n][n1+1][n2+1][n3+1];
z=0;
if (mx>10)z=100;
if (mx<-10)z=100;
if (z>50)mx=0;
v1=u1+v[n-1][n2+1][n3+1][mx+10];
if (z>50)v1=-999;
if (v1>maxv)nxs=n3;
if (v1>maxv)mxs=mx;
if (v1>maxv)maxv=v1;
}
goton[n][n1+1][n2+1][m+10]=nxs;
gotom[n][n1+1][n2+1][m+10]=mxs;
v[n][n1+1][n2+1][m+10]=maxv;
}
}
}
}
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
u1=endu[n1+1][n2+1];
mx=-endbx[n1+1][n2+1];
z=0;
if (mx>10)z=100;
if (mx<-10)z=100;
if (z>50)mx=0;
v1=u1+v[9][n1+1][n2+1][mx+10];
if (z>50)v1=-999;
endv[n1+1][n2+1]=v1;
endm[n1+1][n2+1]=mx;
}
}
maxv=-999;
ns1=0;
ns2=0;
ms=0;
for (n1=-1; n1<2;n1++){
for (n2=-1; n2<2;n2++){
if (endv[n1+1][n2+1]>maxv)ns1=n1;
if (endv[n1+1][n2+1]>maxv)ns2=n2;
if (endv[n1+1][n2+1]>maxv)ms=endm[n1+1][n2+1];
if (endv[n1+1][n2+1]>maxv)maxv=endv[n1+1][n2+1];
}
}
op[10]=ns1;
op[9]=ns2;
op[8]=goton[9][op[10]+1][op[9]+1][ms+10];
ms=goton[9][op[10]+1][op[9]+1][ms+10];
for (j=1;j<8;j++){
n=8-j;
op[n]=goton[n+1][op[n+2]+1][op[n+1]+1][ms+10];
ms=goton[n+1][op[n+2]+1][op[n+1]+1][ms+10];
}
for (n=0;n<11;n++){
c[n]=c[n]+op[n]*h;
}
if (maxv==supv)h=h/2;
if (maxv>supv)supv=maxv;
if (h<0.0001)t=10000;
System.out.println(maxv);
t=t+1;
}
for (s=1;s<100;s++){
n=prefer(s,c,y,th);
c1=c[n];
y1=y[n];
n=prefer(s+1,c,y,th);
dc=c[n]-c1;
dy=y[n]-y1;
if (dy>0)System.out.println(1-dc/dy);
}
}
static double u(double c1,double l1){
int pp;
double u1,cp,lp;
pp=0;
cp=c1;
lp=l1;
if (lp<0)pp=100;
if (cp<0)pp=100;
if (cp==0)pp=100;
if (lp>0.99)pp=100;
if (pp>50)lp=0.5;
if (pp>50)cp=0.5;
u1=Math.log(cp)+Math.log(1-lp);
if (pp>50)u1=-999;
return u1;
}
static double trs(double tl,double[] y,double[] th){
double tr1,tr2,tr3,b1,b2;
double c[]=new double[11];
int t,n;
tr1=0.1;
tr2=0.2;
for (n=0; n<11;n++){
c[n]=(1-tl)*y[n]+tr1;
}
b1=bud(c,y,th);
t=0;
while (t<100){
for (n=0; n<11;n++){
c[n]=(1-tl)*y[n]+tr2;
}
b2=bud(c,y,th);
tr3=tr2-b2*(tr2-tr1)/(b2-b1);
tr1=tr2;
tr2=tr3;
b1=b2;
if (b1*b1<0.001)t=1000;
t=t+1;
}
return tr2;
}
static double bud(double[] c,double[] y,double[] th){
int n,s;
double b1;
b1=0;
for (s=1; s<101;s++){
n=prefer(s,c,y,th);
b1=b1+y[n]-c[n];
}
return b1;
}
static double wel(double[] c,double[] y,double[] th){
int n,s;
double w1;
w1=0;
for (s=1; s<101;s++){
n=prefer(s,c,y,th);
w1=w1+u(c[n],y[n]/th[s]);
}
return w1;
}
static double seekfastb(int n1,int n2, int[] gr,double[] c,double[] y,double[] th,double h){
double sumb,c1,c2,c3,l1,l2,l3,u1,u2,u3,maxu,maxl,maxc;
int s,j;
sumb=0;
for (s=1; s<101;s++){
j=0;
if (gr[s]==0)j=100;
c1=c[0]+n1*h;
l1=y[0]/th[s];
u1=u(c1,l1);
c2=c[1]+n2*h;
l2=y[1]/th[s];
u2=u(c2,l2);
maxc=c1;
maxl=l1;
maxu=u1;
if (u2>maxu)maxl=l2;
if (u2>maxu)maxc=c2;
if (u2>maxu)maxu=u2;
if (j>50)sumb=sumb+th[s]*maxl-maxc;
}
return sumb;
}
static double seekendb(int n1,int n2, int[] gr,double[] c,double[] y,double[] th,double h){
double sumb,c1,c2,c3,l1,l2,l3,u1,u2,u3,maxu,maxl,maxc;
int s,j;
sumb=0;
for (s=1; s<101;s++){
j=0;
if (gr[s]==10)j=100;
c1=c[9]+n1*h;
l1=y[9]/th[s];
u1=u(c1,l1);
c2=c[10]+n2*h;
l2=y[10]/th[s];
u2=u(c2,l2);
maxc=c1;
maxl=l1;
maxu=u1;
if (u2>maxu)maxl=l2;
if (u2>maxu)maxc=c2;
if (u2>maxu)maxu=u2;
if (j>50)sumb=sumb+th[s]*maxl-maxc;
}
return sumb;
}
static double seekb(int n,int n1,int n2,int n3, int[] gr,double[] c,double[] y,double[] th,double h){
double sumb,c1,c2,c3,l1,l2,l3,u1,u2,u3,maxu,maxl,maxc;
int s,j;
sumb=0;
for (s=1; s<101;s++){
j=0;
if (gr[s]==n)j=100;
c1=c[n-1]+n1*h;
l1=y[n-1]/th[s];
u1=u(c1,l1);
c2=c[n]+n2*h;
l2=y[n]/th[s];
u2=u(c2,l2);
c3=c[n+1]+n3*h;
l3=y[n+1]/th[s];
u3=u(c3,l3);
maxc=c1;
maxl=l1;
maxu=u1;
if (u2>maxu)maxl=l2;
if (u2>maxu)maxc=c2;
if (u2>maxu)maxu=u2;
if (u3>maxu)maxl=l3;
if (u3>maxu)maxc=c3;
if (u3>maxu)maxu=u3;
if (j>50)sumb=sumb+th[s]*maxl-maxc;
}
return sumb;
}
static double seekfastu(int n1,int n2, int[] gr,double[] c,double[] y,double[] th,double h){
double sumu,c1,c2,l1,l2,u1,u2,maxu,maxl,maxc;
int s,j;
sumu=0;
for (s=1; s<101;s++){
j=0;
if (gr[s]==0)j=100;
c1=c[0]+n1*h;
l1=y[0]/th[s];
u1=u(c1,l1);
c2=c[1]+n2*h;
l2=y[1]/th[s];
u2=u(c2,l2);
maxu=u1;
if (u2>maxu)maxu=u2;
if (j>50)sumu=sumu+maxu;
}
return sumu;
}
static double seekendu(int n1,int n2, int[] gr,double[] c,double[] y,double[] th,double h){
double sumu,c1,c2,l1,l2,u1,u2,maxu,maxl,maxc;
int s,j;
sumu=0;
for (s=1; s<101;s++){
j=0;
if (gr[s]==10)j=100;
c1=c[9]+n1*h;
l1=y[9]/th[s];
u1=u(c1,l1);
c2=c[10]+n2*h;
l2=y[10]/th[s];
u2=u(c2,l2);
maxu=u1;
if (u2>maxu)maxu=u2;
if (j>50)sumu=sumu+maxu;
}
return sumu;
}
static double seeku(int n,int n1,int n2,int n3, int[] gr,double[] c,double[] y,double[] th,double h){
double sumu,c1,c2,c3,l1,l2,l3,u1,u2,u3,maxu,maxl,maxc;
int s,j,pc;
sumu=0;
pc=0;
for (s=1; s<101;s++){
j=0;
if (gr[s]==n)j=100;
c1=c[n-1]+n1*h;
l1=y[n-1]/th[s];
u1=u(c1,l1);
c2=c[n]+n2*h;
l2=y[n]/th[s];
u2=u(c2,l2);
c3=c[n+1]+n3*h;
l3=y[n+1]/th[s];
u3=u(c3,l3);
maxu=u1;
if (u2>maxu)maxu=u2;
if (u3>maxu)maxu=u3;
if (j>50)sumu=sumu+maxu;
if (u2==maxu)pc=100;
}
if (pc<50)sumu=-999;
return sumu;
}
static int prefer(int s,double[] c,double[] y,double[] th){
int n,maxn;
double maxu;
double c1,l1,u1;
maxu=-999;
maxn=0;
for (n=0;n<11;n++){
c1=c[n];
l1=y[n]/th[s];
u1=u(c1,l1);
if (u1>maxu)maxn=n;
if (u1>maxu)maxu=u1;
}
return maxn;
}
}
最終更新:2010年05月16日 13:08