public void search(int begin, String s, List<Integer> path, boolean[][] isWord, boolean[] possible,
                       List<String> res) {
        if (!possible[begin])
            return;
        if (begin >= s.length()) {
            StringBuilder sb = new StringBuilder();
            int start = 0;
            for (int i = 0; i < path.size() - 1; ++i) {
                int index = path.get(i);
                sb.append(s.substring(start, index) + " ");
                start = index;
            }
            sb.append(s.substring(start, path.get(path.size() - 1)));
            res.add(sb.toString());
            return;
        }
        for (int i = begin; i < s.length(); ++i) {
            if (!isWord[begin][i])
                continue;
            path.add(i + 1);
            search(i + 1, s, path, isWord, possible, res);
            path.remove(path.size() - 1);
        }
    }