33333333333333333333333333333333333333333333

private List<String> seg(String str) {
        // get all paths like this:
//        0  [3, 1, 2]
//        1  [2]
//        2  [4, 3]
//        3  [4]
//        4  [5]
//        5  [7, 6]
//        6  [7]

        IntArray[] paths = new IntArray[str.length()];
        char[] chars = str.toCharArray();
        for (int i = 0; i < str.length(); i++) {
            IntArray path = new IntArray(1);
            int max = TRIE.maxMatch(chars, i, chars.length - i);
            path.add(i + max);

            for (int j = 1; j < max; j++) {
                if (TRIE.contains(chars, i, j)) {
                    path.add(i + j);
                }
            }
            paths[i] = path;
        }


        // 动态规划自下向上开始计算, 每个节点算出最大的分数, 同时记录其下一个节点
        // 获取的nexts路径像这样: [2, 2, 4, 4, 5, 7, 7]
        float[] maxScores = new float[str.length() + 1];
        maxScores[str.length()] = 0;
        int[] nexts = new int[str.length()];

        for (int i = str.length() - 1; i >= 0; i--) {
            float maxScore = Float.NEGATIVE_INFINITY;
            int next = 0;
            for (int j = 0; j < paths[i].size(); j++) {
                int possibleNext = paths[i].get(j);
                float score = TRIE.weight(chars, i, possibleNext - i) + maxScores[possibleNext];
                if (score > maxScore) {
                    maxScore = score;
                    next = possibleNext;
                }
            }
            maxScores[i] = maxScore;
            nexts[i] = next;
        }

        List<String> terms = new ArrayList<>(4);

        int current = 0;
        while (current != str.length()) {
            int next = nexts[current];
            String term = str.substring(current, next);
            terms.add(term);
            current = next;
        }
        return terms;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计质量管理办法要点解读输变电工程设计

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值