#include<iostream>
using std::cout;
using std::endl;
#define max(a,b) (((a)>(b))? (a):(b))
#define N 4
void print(int [][N]);
int matrixPath(int [][N]);
int main(){
 int m[N][N] = {{6,7,1,5},{5,3,1,8},{7,1,3,3},{8,1,4,9}};
 
 print(m);
 cout<<matrixPath(m)<<endl;
system("PAUSE");
 return 0;
}
 int matrixPath(int m[][N])
{
int c[N][N] = {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
c[0][0]=m[0][0];
 for (int i=1;i<N;i++)
  c[i][0]=m[i][0]+c[i-1][0];
 for (int j=1;j<N;j++)
 c[0][j]=m[0][j]+c[0][j-1];
 for (int i=1;i<N;i++){
  for (int j=1;j<N;j++)
  {
  c[i][j]=m[i][j]+max(c[i-1][j],c[i][j-1]);
  }
 }
cout<<"------------------"<<endl;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
cout<<c[i][j]<<"  ";
}
cout<<endl;
}
return c[N-1][N-1];
}
 void print(int m[][N]){
 
 int i,j;
for(i=0;i<N;i++){
for(j=0;j<N;j++){
cout<<m[i][j]<<"  ";
}
cout<<endl;
}
}
'Not Using > algorithm' 카테고리의 다른 글
| DP (0) | 2009.12.01 | 
|---|---|
| 해쉬테이블 완성 (0) | 2009.11.09 | 
| 완성못한 해쉬테이블 (0) | 2009.11.03 | 
| 이런망할이진검색트리 (0) | 2009.10.27 | 
| 알고리즘 --- (0) | 2009.10.13 |