#include<stdio.h> #include<math.h> #include <stdlib.h> float A[3][3]={0.5,0.2,0.3, 0.3,0.5,0.2, 0.2,0.3,0.5}; float B[3][2]={0.5,0.5, 0.4,0.6, 0.7,0.3}; int o[4]={0,1,0,1},t=4; float pi[3]={0.2,0.4,0.4}; float b[4][4]={0}; int main() { int i,j,z; float q=0; for(i=0;i<3;i++) b[3][i]=1; for(z=3;z>0;z--) { for(i=0;i<3;i++) { q=0; for(j=0;j<3;j++) q=A[i][j]*B[j][o[z]]+q; b[z-1][i]=q*b[z][i]; } } q=0; for(i=0;i<3;i++) q=q+pi[i]*B[i][o[0]]*b[0][i]; printf("%f",q); }