0% found this document useful (0 votes)
12 views3 pages

Daa Program No 10

Uploaded by

ankush8522109
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Daa Program No 10

Uploaded by

ankush8522109
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Anisha March 28,2024

(8522107)

Program No. 10

Aim: Write a program to implement matrix chain multiplication using


dynamic programming.

Description: Matrix chain multiplication is an optimization problem in which


the goal is to find the most efficient way to multiply the given matrices. This
problem is solved using dynamic programming as it contain overlapping sub
problem in order to find the minimum number of multiplication.

Source code:

#include<stdio.h>

void mcm(int p[],int n)

int m[n][n],s[n][n];

int i,j,k,l,q,max;

max=32767;

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]=max;

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])

Page No.26
Anisha
(8522107)
{

m[i][j]=q;

s[i][j]=k;

printf(" Minimum matrix multiplication are %d,%d\n",m[i][j-l],s[i][j-l]);

int main()

int ns,arr[10],i;

printf("Enter the number of matrix\n");

scanf("%d",&ns);

ns++;

arr[ns];

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

printf("Enter d%d::",i);

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

mcm(arr,ns);

return 0;

Output:

Page No.27
Anisha
(8522107)

Page No.28

You might also like