1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include<iostream> #include<cstring> using namespace std; string a,b; int f[2010][2010]; int Dfs(int i, int j){ if(f[i][j]!=-1) return f[i][j]; if(i==0) return f[i][j]=j; if(j==0) return f[i][j]=i; int c=1; if(a[i-1]==b[j-1]) c=0; return f[i][j]=min(min(Dfs(i-1,j)+1,Dfs(i,j-1)+1),Dfs(i-1,j-1)+c); } int main(){ cin>>a>>b; memset(f,-1,sizeof(f)); int len1=a.length(),len2=b.length(); Dfs(len1,len2); cout<<f[len1][len2]; return 0; } |
0 of 6 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 6 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
22. 第7行和第20行的-1如果改成-2,程序运行结果可能不一样( )。
23. n是输入两个字符串长度的最大值,程序的时间复杂度为log(n)( )。
24. 输出的最小值为-1( )。
25. 设len1和len2为执行完第21行后的值,则程序输出的最大值为len1+len2( )。
26. 输入为sfdqxbw gfdgw,输出( )。
27. 保证输入的两个字符串长度均为 100,且只包含小写字母 a~z,第一个字符串为”acegikmoqsuwyace…uwy…ace…moq”,
第二个字符串为”abcdefghijklmnopqrstuvwxy…abc…wxyabcd”(“…”表示省略了中间的字符),输出为( )