#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#define DELPOINTER(p) if(nullptr!=(p)){delete[] (p),(p)=nullptr;}
#define DO(sth) for (DLXNode * pCol = pRow->right; pCol != pRow; pCol = pCol->right) {\
(sth)(pCol->elem.c);\
}
using namespace std;
int ans[1000];
unordered_map<int, int> m;
struct ElemType {
int r, c;
ElemType(const int & _r = int(), const int & _c = int()) :r(_r), c(_c) {}
};
struct DLXNode {
ElemType elem;
DLXNode *up, *left, *down, *right;
DLXNode(const ElemType & _elem = ElemType(),
DLXNode * _up = nullptr, DLXNode * _left = nullptr, DLXNode * _down = nullptr, DLXNode * _right = nullptr)
:elem(_elem), up(_up), left(_left), down(_down), right(_right) {}
};
class DLX {
public:
DLX(const int & _row, const int & _col);
DLX(const vector<vector<int> > & mtx);
~DLX(void);
inline void addNode(const int & x, const int & y);
/* 双向链表的断开与连接操作 */
/* U L D R */
/* 上 左 下 右 */
inline void deleteUD(DLXNode * p);
inline void deleteLR(DLXNode * p);
inline void resumeUD(DLXNode * p);
inline void resumeLR(DLXNode * p);
void cover(const int & col);
void uncover(const int & col);
bool dance(const int & step);
inline DLXNode* getNode(const int & index);
private:
void init(const int & row, const int & col);
inline bool empty() { return m_pHead->left == m_pHead; }
inline int getMinColPos(); // 获取当前所有列中元素个数最小的一列
private:
int m_nIndex; // 有多少个节点
int m_nRowCount; // 行数
int m_nColCount; // 列数
int * m_pS