Matrix chain order problem with the code

M

mojo

I have my code pretty much done except I have a few problems that I
need to fix and can't really quite remember how to fix them. Thanks for
the help

Error 1:cannot convert from 'const int' to 'int [6]'
Error 2:cannot add two pointers
Error 3:no conversion from 'int *' to 'int'
Error 4:'int' differs in levels of indirection from 'int [6]'

I have labeled my code with the listed errors above.
This code should output the Recursive Matrix Chain (which is fine) and
the Matrix chain order(which has problems).

#include <iomanip>
#include <iostream>
#include <cstdlib>

using namespace std;

const int SIZE = 6;
const int MAX = 999999;

int M[SIZE][SIZE];

int P[SIZE + 1] = { 5, 10, 3, 12, 5, 50, 6};

int Recursive_Matrix(int i, int j);
void Print_M();
int Matrix_Chain_Order();


int main()
{
Recursive_Matrix( 0, SIZE - 1);
Print_M();
return 0;
}

int Recursive_Matrix(int i, int j)
{
int q;

if( i == j )
return 0;
else
{
M[j] = MAX;
for(int k = i; k <= j - 1; k++)
{
q = Recursive_Matrix(i, k);
q += Recursive_Matrix( k+1, j);
q += P * P[k + 1] * P[j + 1];
if( q < M[j])
M[j] = q;
}
}
return M[j];
}


void Print_M()
{
for(int x = 0; x < SIZE; x++)
{
for(int y = 0; y < SIZE; y++)
{
cout << setw(7) << M[x][y];
}
cout << endl;
}
}

int Matrix_Chain_Order()
{
int n = SIZE;
int s[SIZE][SIZE];

for (int i=1;i<=n;i++)
{ M[i,i] = 0; } //Error 1
for (int l=2;l<=n;l++){
for (int i=1;i<=n-l+1;i++)
{
int j = i+l-1;
M[i,j] = MAX;//Error 1
for(int k=i;k<=j-1;k++)
{
int q = M[i,k] + M[k+1,j] + P[i-1]*(P[k])*(P[j]);//Error 2
if(q<M[i,j])//Error 3 and Error 4
{
M[i,j] = q;//Error 1
s[i,j] = k;//Error 1
}
}
}
}
}
 
E

eddy_ruslim

isnt M[i,i] should be M?
I think M[i,i] is for VB.
Just a thought thought
thoughtthoughtthoughtthought real strange things
well that then then, got to get my children report worked up (church)

dernity
---------
if it help
please help me provide better school supplies for childrenof indonesia.
it may be a donation but I merely ask you to letme send email to you
from one of the product of I'm affiliated and please register there on
mechant account free. If you even want you refund back on your dollar
of i-kard, its ok, I'll send you just use regular delivery on shipping
please. Please note this is very safe since this is a bonafid company.
remember your credit card company will confirm you on your purchase.
Still have doubts, sign on a personal account and let me contact you
again on it. just one mail pls
also
I'm also affiliated to this site:
www.getaportal.com/portals/eddy_ruslim
Unless u wanto e-gold it at 1369872
New to egold:www.e-gold.com/e-gold.asp?cid= 1369872
NAH, previous way cost u zilch
 
R

Rolf Magnus

mojo said:
I have my code pretty much done except I have a few problems that I
need to fix and can't really quite remember how to fix them. Thanks for
the help

Error 1:cannot convert from 'const int' to 'int [6]'
Error 2:cannot add two pointers
Error 3:no conversion from 'int *' to 'int'
Error 4:'int' differs in levels of indirection from 'int [6]'

I have labeled my code with the listed errors above.
This code should output the Recursive Matrix Chain (which is fine) and
the Matrix chain order(which has problems).

{ M[i,i] = 0; } //Error 1

M[i,i] is equivalent to M. I guess you meant M. The other errors
are just for the same reason.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top