枚举中间可能出现的天气

 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
const int maxn = ;
double mat[ ][ ]; void solve( int L,int R,int n ){
double ans[ ],tp[ ];
double res = ;
for( int i=;i<=n;i++ ){
if( i== ){
ans[ ] = mat[ L ][ ];
ans[ ] = mat[ L ][ ];
ans[ ] = mat[ L ][ ];
//printf("i = 1: %lf %lf %lf\n",ans[1],ans[2],ans[3]);
continue;
}
else if( i==n ){
res = ans[ ]*mat[ ][ R ];
res += ans[ ]*mat[ ][ R ];
res += ans[ ]*mat[ ][ R ];
continue;
}
else {
tp[] = ans[],tp[] = ans[],tp[] = ans[];
ans[ ] = tp[ ]*mat[ ][ ]+tp[ ]*mat[ ][ ]+tp[ ]*mat[ ][ ];
ans[ ] = tp[ ]*mat[ ][ ]+tp[ ]*mat[ ][ ]+tp[ ]*mat[ ][ ];
ans[ ] = tp[ ]*mat[ ][ ]+tp[ ]*mat[ ][ ]+tp[ ]*mat[ ][ ];
// ans[1] = tp[1],ans[2] = tp[2],ans[3] = tp[3];
//printf("i = %d: %lf %lf %lf\n",i,ans[1],ans[2],ans[3]);
continue;
}
}
printf("%.3lf\n",res);
} int main(){
//freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
while( T-- ){
for( int i=;i<=;i++ ){
for( int j=;j<=;j++ ){
scanf("%lf",&mat[ i ][ j ]);
}
}
int K;
scanf("%d",&K);
while( K-- ){
int L,R,N;
scanf("%d%d%d",&L,&R,&N);
if( N== ){
printf("%.3lf\n",mat[ L ][ R ]);
continue;
}
solve( L,R,N );
}
}
return ;
}
05-02 19:26