Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
464 views
in Technique[技术] by (71.8m points)

algorithm - 如果在最长的公共子序列中使用min而不是max会发生什么?(What will happen if we use min instead of max in longest common sub sequence?)

Consider below code stuff of the dynamic programming approach of the LCS.

(考虑以下LCS动态编程方法的代码。)

int lcs( char[] X, char[] Y, int m, int n ) 
 { 
if (m == 0 || n == 0) 
  return 0; 
if (X[m-1] == Y[n-1]) 
  return 1 + lcs(X, Y, m-1, n-1); 
else
  return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n)); 
 } 

As we can see if X[m-1] != Y[n-1], we take the max value among given two lcs values.

(如我们所见,如果X [m-1]!= Y [n-1],我们取给定两个lcs值中的最大值。)

So, my problem is what happens if we change max to min as below.

(所以,我的问题是,如果我们将max更改为min,将会发生什么情况。)

return min(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));

I mean, what would be my final out come if I changed the return statement as above?.

(我的意思是,如果我如上所述更改return语句,最终结果将是什么?)

  ask by TTDS translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...