answersLogoWhite

0

# include <stdio.h>

# include <conio.h>

# include <stdlib.h>

# define sz 20

# define INF 200000

void print(unsigned long s[][sz], int i, int j)

{

if (i == j)

printf(" A%d ",i);

else

{

printf(" ( ");

print(s, i, s[i][j]);

print(s, s[i][j] + 1, j);

printf(" ) ");

}

}

void printm(unsigned long m[][sz], int n)

{

int i,j;

for(i=1;i<=n;i++)

{

for(j=1;j<=n;j++)

{

printf("%5d",m[i][j]);

}

printf("\n\n");

}

printf("\nThe No. of multiplication required is : %d",m[1][n]);

}

void Matrix_Chain_Order(int p[],int num)

{

unsigned long m[sz][sz] = {0};

unsigned long s[sz][sz] = {0};

unsigned int q = 0;

int i, j, k, l;

int n = num;

for(i = 1; i <= n; i++)

m[i][i] = 0;

for(l = 2; l <= n; l++)

for(i = 1; i <= (n - l + 1); i++)

{

j = i + l - 1;

m[i][j] = INF;

for(k = i; k <= j - 1; k++)

{

q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];

if(q < m[i][j])

{

m[i][j] = q;

s[i][j] = k;

}

}

}

print(s, i-1, j);

printf("\n\n");

printf("The Minimum No. of Multiplication Required is:\n\n");

printm(m,n);

}

void main()

{

int i,num=0,p[sz]={0};

clrscr();

printf("Enter the number of matrix : ");

scanf("%d",&num);

printf("Enter %d no. of order sequence for %d matrix :\n",num+1,num);

for(i=0;i<=num;i++)

scanf("%d",&p[i]);

printf("\n\n");

printf("MULTIPLICATION SEQUENCE IS : ");

printf("\n\n\t");

Matrix_Chain_Order(p,num);

getch();

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Continue Learning about Engineering

What are the main uses of the Healthcare EDI program?

Healthcare EDI Solutions program has two main uses; firstly, it provides Chain Management (CM) and secondly, it also provides health care EDI technology claims management and Patient Information Exchange (PIE).


What statement is like a chain of if then else statements they perform their tests one after the other until one of them is found to be true?

Language-dependent, it can be switch, select, case or something similar.


What is a rope with or a chain around it called?

A rope with a chain around it is typically referred to as a &quot;rope chain&quot; or &quot;rope and chain combination.&quot; This setup is often used for added strength and durability, combining the flexibility of rope with the rigidity of a chain. In some contexts, it may also be called a &quot;chain rope.&quot;


How does a chain hoist work?

A chain hoist uses gears to multiply force.A chain hoist is operated by hand. An operator pulls the light loop chain on the side of the chain hoist. This turns a gear mechanism inside the chain hoist housing to turn the chain pulley. When this pulley turns, it raises the heavy chain which usually has a hook on the end. By pulling the light chain loop, the manual hoist is actually able to increase the force that is being applied by the heavy chain. This is caused by the gear ratios inside the manual chain hoist. The mechanical work done by the operator is the same as the work done by the heavy lifting chain.


What is Green supply chain?

Green Supply Chain Supply chain management with an emphasis on energy efficiency and environmental friendliness.