查字典的DP解法
来源:互联网 发布:2015年度网络流行语 编辑:程序博客网 时间:2024/04/29 14:15
s = "aaaaaaaaaaaaaaaaaaaaaaaaaaab";
dict = ["a","aa",""aaa","aaaab","aaaaaac"];
用一个boolean数组can,记录从0-i的字符串能否在字典中找到,can[i]表示substring[0,i]可以在字典中匹配。
public boolean wordBreak(String s, Set<String> dict)
{int length = s.length();
boolean can[] = new boolean[length+1];
can[0] = true;
for(int i = 0 ; i <= length; i++){
for(int j = 0;j<i ; j++ ){
if(can[j] && dict.contains(s.substring(j,i))){
can[i] =true;
break;
}
}
}
return can[length];
}
0 0
- 查字典的DP解法
- 查字典
- 查字典
- 一个dp问题的解法
- [poj 1014]Dividing的DFS解法解读和DP解法
- 区间DP 的两种解法
- 几个常见的DP问题及解法
- 几个常见的DP问题及解法
- hdu 1058 dp解法
- 关于Web搜索-查字典式的Web搜索
- 我的作品 电子元件替换速查字典V5.0
- 对网上最大字段和dp解法建模的勘误
- 最长公共上升子序列的DP解法及其优化
- Palindrome Partitioning I,II[leetcode] DFS以及DP的解法
- 装配线问题—类似于树形dp的解法
- 最长公共子序列(LCS问题)的DP解法
- 最长公共上升子序列的DP解法及其优化
- 最长公共上升子序列的DP解法及其优化
- JDBC 连接mysql数据库
- NYOJ638 Take it easy II
- 当我们的经验无法适应新环境的时候该怎么办? Covariate Shift
- 社会工程学之父
- 笔记---002
- 查字典的DP解法
- 使用EasyBCD引导安装Ubuntu系统
- 封装 获取后台数据类
- Python学习笔记(四)—生成随机数
- 14.3.2 english
- Ubuntu 升级内核
- C++单例模板
- struts2的开发模式
- ”易“”难“计算器