private void totalNQueens2Rec(int level, List<Integer> perm){
        if (level == perm.size() && isValid(perm)) ++res;
        for (int i = level; i < perm.size(); ++i){
            Collections.swap(perm, i, level);
            totalNQueens2Rec(level + 1, perm);
            Collections.swap(perm, i, level);
        }
    }