Changes
no edit summary
<p> </p>
<h2>Dynamic Program</h2>
<p>def maxvalue(a,b,c):<br />
a=a+5<br />
b=b-6<br />
c=c-6<br />
return max(a,b,c)<br />
def maxvalue2(a,b,c):<br />
a=a-2<br />
b=b-6<br />
c=c-6<br />
return max(a,b,c)</p>
<p>def compare(a,b):<br />
import numpy as np<br />
scoring = np.zeros([len(a)+1,len(b)+1])<br />
for i in range(0,len(a)+1):<br />
scoring[i,0]=-6*i<br />
for j in range(0,len(b)+1):<br />
scoring[0,j]=-6*j</p>
<p> for row in range(1,len(a)+1):<br />
for column in range(1,len(b)+1):<br />
if b[column-1]==a[row-1]:<br />
scoring[row,column] = maxvalue(scoring[row-1,column-1],scoring[row-1,column],scoring[row,column-1])<br />
if b[column-1]!=a[row-1]:<br />
scoring[row,column] = maxvalue2(scoring[row-1,column-1],scoring[row-1,column],scoring[row,column-1])<br />
print(scoring)</p>
<p> list=[]<br />
for row in range(1,len(a)+1):<br />
for column in range(1,len(b)+1):<br />
new=scoring[row,column]<br />
list.append(new)<br />
mxv=max(list)<br />
print(mxv)</p>
<p><img alt="" src="/ckfinder/userfiles/images/bandicam%202017-12-12%2019-14-32-803.jpg" style="height:530px; width:640px" /></p>