当前位置:网站首页>Dynamic planning - force buckle
Dynamic planning - force buckle
2022-07-23 15:08:00 【Love and hard reality】
List of articles
Dynamic programming
Edit distance

analysis
- There are three ways to make dynamic changes in the topic , Insert 、 Delete and modify a character .
Delete m[i][j] = m[i - 1][j] + 1
Change m[i][j] = m[i - 1][j - 1] + 1
increase m[i][j] = m[i ][j - 1] + 1 - The initial state : If no one can match, the whole word length is required .
m[i][0] = i
m[0][j] = j
Code
class Solution {
public int minDistance(String word1, String word2) {
/* a[i - 1] -> b[j - 1] k => a[i] -> b[j] k + 1 a[i - 1] -> b[j] k => a[i] -> b[j] k + 1 a[i] -> b[j - 1] k => a[i] -> b[j] k + 1 m[i][0] = i m[0][j] = j */
char[] w1 = word1.toCharArray();
char[] w2 = word2.toCharArray();
final int l1 = w1.length;
final int l2 = w2.length;
int[][] m = new int[l1 + 1][l2 + 1];
for (int i = 0; i <= l1; i++) {
m[i][0] = i;
}
for (int i = 0; i <= l2; i++) {
m[0][i] = i;
}
for (int i = 1; i <= l1; i++) {
for (int j = 1; j <= l2; j++) {
if (w1[i - 1] == w2[j - 1]) {
m[i][j] = m[i - 1][j - 1];
} else {
m[i][j] = 1 + Math.min(m[i -1][j - 1], Math.min(m[i - 1][j], m[i][j - 1]));
}
}
}
return m[l1][l2];
}
}
边栏推荐
- Qt| imitation text floating letter
- Matlab simulation of solving multi-objective optimal value based on PSO optimization
- 力扣-单调栈
- Prometheus入门使用(三)
- Head pose estimation principle and visualization_ Loveliuzz's blog - Programmer's Homestead_ Head posture estimation
- Feignclient utilise un tutoriel détaillé (illustration)
- 【无标题】
- Simulation of voltage source PWM rectifier with double closed loop vector control based on Simulink
- @FeignClient使用詳細教程(圖解)
- [solve the exception] Flink uploads the jar package to the cluster environment, and the operation report does not serialize the exception
猜你喜欢

【OpenCV 例程200篇】225. 特征提取之傅里叶描述子

Simulation of BOC modulation signal acquisition based on MATLAB

Full backpack!

如何实现多个传感器与西门子PLC之间485无线通讯?
![[test platform development] 20. Complete the function of sending interface request on the edit page](/img/ab/fed56b5bec990a25303c327733a8e6.png)
[test platform development] 20. Complete the function of sending interface request on the edit page

易基因|靶基因DNA甲基化测序(Target-BS)

基於matlab的CBOC信號調制解調仿真,輸出其相關性,功率譜以及頻偏跟踪

The pit trodden by real people tells you to avoid the 10 mistakes often made in automated testing

MariaDB 数据库升级版本

动态规划-力扣
随机推荐
精品国创《少年歌行》数字藏品开售,邀你共铸少年武侠江湖梦
Advanced operation and maintenance 02
安全7.18作业
Full backpack!
一道代码题看 CommonJS 模块化规范
MySQL unique index has no duplicate value, and the error is repeated
【7.16】代码源 -【数组划分】【拆拆】【选数2】【最大公约数】
RSA加密的使用
NVIDIA vid2vid论文复现
Live classroom system 03 supplement model class and entity
Jetpack系列之Room中存Map结构
深入理解CAS (自旋锁)
基于matlab的BOC调制信号捕获仿真
581. Shortest unordered continuous subarray
day18
力扣-单调栈
Matlab simulation of Turbo code error rate performance
@Feignclient detailed tutorial (illustration)
【启发式分治】启发式合并的逆思想
用FFT加速特殊矩阵的矩阵向量乘运算