We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
参考python版本计算动态规划的逻辑,将CalcDP函数的计算顺序改为从后往前就可以了。 可直接替换代码如下:
void CalcDP(vector& dags) const { size_t dagSize = dags.size(); size_t nextPos; const DictUnit* p; double val;
for(size_t i = 0; i < dagSize; i++){ dags[dagSize - i - 1].pInfo = NULL; dags[dagSize - i - 1].weight = MIN_DOUBLE; assert(!dags[dagSize - i - 1].nexts.empty()); for(LocalVector<pair<size_t, const DictUnit*> >::const_iterator it = dags[dagSize - i - 1].nexts.begin(); it != dags[dagSize - i - 1].nexts.end(); it++) { nextPos = it->first; p = it->second; val = 0.0; if(nextPos + 1 < dags.size()) { val += dags[nextPos + 1].weight; } if(p) { val += p->weight; } else { val += dictTrie_->GetMinWeight(); } if(val > dags[dagSize - i - 1].weight) { dags[dagSize - i - 1].pInfo = p; dags[dagSize - i - 1].weight = val; } } }
}
The text was updated successfully, but these errors were encountered:
解决的bug,能举例几个吗
Sorry, something went wrong.
作者本来用的就是从后往前遍历的逻辑(rbegin/rend) 见代码: https://github.com/yanyiwu/cppjieba/blob/master/include/cppjieba/MPSegment.hpp#L85
No branches or pull requests
参考python版本计算动态规划的逻辑,将CalcDP函数的计算顺序改为从后往前就可以了。
可直接替换代码如下:
void CalcDP(vector& dags) const {
size_t dagSize = dags.size();
size_t nextPos;
const DictUnit* p;
double val;
}
The text was updated successfully, but these errors were encountered: