How to calculate the value of a string formula

Updated on technology 2024-07-19
2 answers
  1. Anonymous users2024-02-13

    Distance. The difference between the two strings s1 and s2 can be determined by calculating their maximum distances.

    The so-called distance:

    Changing s1 and s2 to the same string requires the minimum number of operations to be done below.

    Turn a character ch1 into ch2

    Delete a character.

    Insert a character. For example. s1

    and s2="1233";

    Then 12433 can be obtained by inserting 4 in the middle of s2, which is consistent with s1.

    Namely. d(s1,s2)

    An insertion operation was performed).

    The nature of distance.

    Calculating the distance between two strings s1+ch1,s2+ch2 has this property:

    d(s1,””

    d(“”s1)

    s1|d(“ch1”,”ch2”)ch1

    ch2d(s1+ch1,s2+ch2)

    min(d(s1,s2)+

    ch1==ch2

    d(s1+ch1,s2),d(s1,s2+ch2) The first property is obvious.

    The second nature:

    Since we define three operations to act as a measure of distance.

    So for CH1, CH2 possible operations only.

    Turn ch1 into ch2

    s1+ch1 and then delete ch1

    d1+d(s1,s2+ch2))

    S1+CH1 is inserted into CH2D

    d(s1+ch1,s2))

    Operations for 2 and 3 can be equated to:

    Add ch1 after s2+ch2

    d=(1+d(s1,s2+ch2))

    Delete ch2 after s2+ch2

    d=(1+d(s1+ch1,s2))

    Thus the property of calculating the distance can be obtained2.

    Complexity analysis.

    From property 2 above, we can see that the computation process presents such a structure (assuming that each layer is marked with the currently calculated string length, and assuming that both string lengths are .

    n As you can see, the complexity of the problem is exponential.

    Target. To the nth power, for longer strings, the time is unbearable.

    Analysis: In the structure above, we find multiple occurrences.

    n-1,n-1),n-1,n-2)……In other words, the structure has overlapping sub-problems. In addition, the optimal substructure of property 2 is present. Conforms to the basic elements of dynamic programming algorithms.

    Therefore, dynamic programming algorithms can be used to reduce the complexity to the polynomial level.

    Dynamic programming solving.

    First, to avoid double counting sub-problems, add two helper arrays.

    One. Save the results of the subissue. m[s1|

    s2|where m[ij

    Represents a substring. s1(0->i)

    And. s2(0->j)

    distance. Two. Saves the distance between characters.

    e[s1|,s2|Thereinto. e[

    i,js[i]s[j]

    Three. New Calculation Expressions.

    Obtained according to nature 1. m[

    m[s1i,0

    s1i|;m[

    0,s2js2j|;

    According to nature 2 obtained. m[i,j

    min(m[i-1,j-1]e[i,j

    m[i,j-1]

    m[i-1,j]

  2. Anonymous users2024-02-12

    Split strings into characters and add numbers and operators to the stack.

    Then, after each operator is found, another operator appears to compare the priority, and the calculation pops up, the parentheses are not counted as operators, and the left parenthesis meets the right parentheses pop up.

    Pay attention to priorities.

    For example, 2*5+3 4

    Add a number -->2*5+3 4

    into 2, into *, into 5, (just about to enter + find * than + priority), out 2 * 5 = 10 into 10, into +, into 3, into (because of the high priority, do not pop up), into 4, just about to enter, found the highest priority) out of 3 4 = 0, into 0, just about to enter, found the highest priority) out of 10 + 0 = 0

    Progress, end.

Related questions
9 answers2024-07-19

Hello, I'm glad you questioned. Take a look below:

is an escape character that represents one (1). >>>More

8 answers2024-07-19

public static void main(string args) {

string str1="abcdefghij"; >>>More

10 answers2024-07-19

The meaning of the title is said upstairs.,Here's a **.。 >>>More

17 answers2024-07-19

Let's talk about the idea first:

Get the last one within this string. location, which is the index. >>>More

16 answers2024-07-19

stuff deletes characters of the specified length and inserts another set of characters at the specified starting point. >>>More