房间分配问题
写了个精确查找的算法 32个学生T2050上单线程 2秒 用TTB 1秒多
核心算法如下
递归调用
void FindBestComb(int* pIndexAry, int nPos, int nStudent, int fCur, int* pMin, int** ppAppetency)
{
int i,j,nTmp;
int fTmp;
if(nPos + 2 == nStudent)
{
fCur += ppAppetency[pIndexAry[nPos]][pIndexAry[nPos+1]];
if(*pMin > fCur) *pMin = fCur;
}
else
{
for(i = nPos + 1; i < nStudent; ++i)
{
fTmp = fCur + ppAppetency[pIndexAry[nPos]][pIndexAry[nPos + 1]];
if(fTmp < *pMin) FindBestComb(pIndexAry, nPos+2, nStudent, fTmp, pMin, ppAppetency);
nTmp = pIndexAry[nPos+1];
for(j = nPos+1; j < nStudent-1; ++j) pIndexAry[j] = pIndexAry[j+1];
pIndexAry[nStudent-1] = nTmp;
}
}
}