Here it is, sorry it took so long to post. i dont have all the resources i'd like to.
Code:
#include <iostream>
enum Consts { LEFT, RIGHT, MAX = 100 };
typedef const unsigned curef;
inline void show(curef costs[], curef where[], curef num, curef cost)
{
for(unsigned i = num; i--; ) if( !where[i] ) cout << costs[ i ] << " " ;
cout << " ................ ";
for(unsigned i = num; i--; ) if( where[i] ) cout << costs[ i ] << " " ;
cout << " : " << cost << endl;
}
void main()
{
unsigned costs[MAX]={1,3,6,8,12}, where[MAX]={0,0,0,0,0}, numCosts=5, cost=0;
const unsigned secMin = costs[1], secMinX2 = (secMin << 1) - costs[0];
show( costs, where, numCosts, cost );
for( unsigned numLeft = numCosts, maxIndex = numCosts - 1, minIndex ; ; --numLeft)
{
if( where[1] ) // if second slowest is on RIGHT
{
where[ maxIndex ] = RIGHT; // move over the slowest
cost+= costs[ maxIndex-- ]; // add cost and move to next slowest
// carry second slowest for the TRICK, or fastest for a normal play
where[ costs[ maxIndex ] > secMinX2 ? maxIndex-- : 0 ] = RIGHT;
}
else
{
where[0] = where[1] = RIGHT; // move 2 fastest to RIGHT side
cost+= secMin ; // add cost of second fastest
}
show( costs, where, numCosts, cost );
if( numLeft == 2 ) break; // if all persons have crossed then stop
// the lamp returner code... when not complete
minIndex = !where[0]; // find the smallest cost on RIGHT side
where[ minIndex ] = LEFT; // move person to the left side
cost+= costs[ minIndex ]; // add the cost of moving the person
show( costs, where, numCosts, cost );
}
}