#include <vector>#include <iostream>#include <queue>#include <stack>using namespace std ; class Bridge_Crossing{ public: Bridge_Crossing(vector<int> &c) ; void generate_solution() ; private: class Node ; vector<Node>states ; //一个状态向量。每一个状态保存一项,共2^(n+1)项 vector<int>costs ; //每个人过河所需要的时间。 int person_num ; void output() ; struct State{ int state ; //状态值。如全在左岸则为0000(binary),过河后该位置1 int direction ; //方向,若在左岸为0,右岸为1 State() { state = direction = 0 ; } State &operator = (const State &s) { state = s.state ; direction = s.direction ; } int hashcode()//计算hash值,即在states向量中的index { return state* 2 +direction ; }} ; struct Node{ int value ; //到该状态所需时间 int previous ; //前一状态的index Node() { value = previous = 0 ; }