//=========================================================================
// File Name: Matrix.h
// Desp : 俄罗斯套娃奖品问题,Matrix类
// Author : 905A组
// Last Update: 2010-05-27 22:35
//=========================================================================
#include <list>
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;
struct eInMat
{
int x;
int y;
int operator == (const eInMat& right) const
{
return x==right.x ? (y==right.y ? 1:0) :0;
}
};
class Matrix
{
public:
Matrix(int countRow,int countCol)
{
nRows=countRow;
nCols=countCol;
int size=countRow*countCol*sizeof(int);
elements=(int*)malloc(size);
padVal=(int*)malloc(size);
memset(padVal,-2,size);
};
~Matrix()
{
free(elements);
free(padVal);
};
int seekMaxGain(eInMat curE,list<eInMat> &vPath);
void outPutPath(list<eInMat> &vPath);
inline int& element(int x)
{
return *(elements+x);
}
inline int& element(eInMat e)
{
return *(elements+nCols*e.x+e.y);
}
private:
int nRows;
int nCols;
int* elements; //用来记录矩阵元素
int* padVal; //用来记录矩阵元素为0时的填充值
int validEMat(eInMat curE); //判断当前元素是否合法,即:是否超出矩阵的边界
int seekMat(eInMat curE,list<eInMat> &vPath);
//判断下一个要遍历的元素是否已在路径vPath中<