Requirements: someone on the ladder, the ladder is 100, you can cross 1 steps once, you can cross 2 steps, you can cross 3 steps once, how many ways to take a ladder? Please also list the number of steps per step (according to the order)!
'High Accuracy Positive Integer Addal and Elevation, That is, the large-scale integer addition and subtraction is' subtraction, known to the first number is mainly used for this program, in order to simplify the code, do not make conversion and symbol judgment, if you want to implement universal Calculate, please adjust the Function DSYS (N1, N2, F) AS String Dim B1 (), B2 (), C, I, and S 'take the large number length segment allocation array size C = IIF (LEN (N1)> LEN (N2), INT (LEN (N1) / 12), INT (LEN (N2) / 12)) 1 REDIM B1 (C 1), B2 (C) S = 0 'N1 Press 12-bit segmentation Deposit in array for i = 1 to LEN (N1) Step 12 s = s 1 if len (n1)> s * 12 THEN B1 (S) = MID (N1, LEN (N1) - S * 12 1, 12 ELSE B1 (S) = MID (N1, 1, LEN (N1) - (S - 1) * 12) End if Next I 'N2 Press 12-bit segmentation to deposit in array s = 0 for i = 1 to LEN (N2) Step 12 S = S 1 IF LEN (N2)> S * 12 THEN B2 (S) = MID (N2, LEN (N2) - S * 12 1, 12) ELSE B2 (S) = MID (N2, 1, LEN (N2) - (S - 1) * 12) End if Next I 'addition IF f = 1 THEN' is added in segment, the result is stored in the array for i = 1 to C B1 (i) = VAL (B1 (i)) VAL (B2 (i)) 'carry if LEN (B1 (i))> 12 THEN B1 (i 1) = VAL (B1 (i 1)) VAL (Left (B1) ( I), LEN (B1 (i)) - 12)) B1 (i) = Right (B1 (i), 12) end IF 'is less than 12 bits 2 dsys = String (12 - len (b1 (i)), "0") & b1 (i) & dsys next I 'subtraction ELSE' is subtracted by segment, the result is stored in the array for i = 1 to C B1 (i) = VAL (B1 (i)) - VAL (B2 (i )) 'Borrow IF B1 (i) <0 THEN B1 (i 1) = VAL (B1 (i 1)) - 1 B1 (i) = VAL (B1 (I)) 10 ^ 12 end if'
Lost 12 位 0 dsys = String (12 - LEN (B1 (i)), "0") & b1 (i) & dsys next i endiff 'going to 0 for i = 1 to Len (DSYS) if MID ( DSYS, I, 1) <> "0" THEN DSYS = MID (DSYS, I) EXIT for End If Next IEND FUNCTION 'Strand Rating Algorithm Function DGZF (T AS Integer, M AS String) AS STRINGDIM I AS INTEGER' Regeneration To the 1st order, the method IF t = 1 damf = "1" exit function 'recursive to the second order ELSEIF T = 2 and m = 2 THEN DGZF = "2" exit function' recursive to 3th order The fourth way of walking ELSEIF T = 3 and m = 4 THEN DGZF = "3" exit function 'If the rule is small equals Elseif Not (DSBJ (M, A (T - 1))))) THEN DGZF = "1" & DGZF (T - 1, M) 'If the number of flasks is small equals Elseif DSBJ (M, A (T - 1)) and NOT (DSBJ (M, DSYS) (T - 1), A (T - 2), 1)))) The DGZF = "2" & DGZF (T - 2, DSYS (M, A (T - 1), 2)) 'If the number of figures is greater than Total number of ELSEIF DSBJ (M, DSYS (A (T - 2), A (T - 2), 1)) THEN DGZF = "3" & DGZF (T - 3, DSYS (DSYS (m, A) (T - 1), 2), A (T - 2), 2)) end ifend function
The following is the program source code, copy the following to the newly created text file, then rename the file suffix name after saving. FRM
VERSION 5.00Begin VB.Form Form1 Caption = "step-down algorithm design" ClientHeight = 4920 ClientLeft = 60 ClientTop = 345 ClientWidth = 6360 LinkTopic = "Form1" ScaleHeight = 4920 ScaleWidth = 6360 StartUpPosition = 3 'default window Begin VB.Frame Frame2 Caption = "Solution:" ForeColor = & H000000FF & Height = 3735 Left = 120 TabIndex = 2 Top = 1080 Width = 6135 Begin VB.CommandButton Command2 Caption = "results Clear" Height = 375 Left = 4560 TabIndex = 11 Top = 240 Width = 1215 End begin vb.textbox text3 height = 270 left = 1080 TabINDEX = 10 TOP = 1155 width = 4935 End Begin vb.commandbutton Comma nd1 Caption = "Solution moves" Default = -1 'True Height = 375 Left = 3000 TabIndex = 9 Top = 240 Width = 1215 End Begin VB.TextBox Text1 Height = 2055 Left = 120 MultiLine = -1' True ScrollBars = 2 'Vertical tabindex = 8 TOP = 1560 width =
5895 End Begin VB.ComboBox Combo1 Height = 300 Left = 1680 Style = 2 'Dropdown List TabIndex = 6 Top = 270 Width = 975 End Begin VB.TextBox Text2 Height = 270 Left = 1080 Locked = -1' True TabIndex = 5 Top = 720 width = 4935 end job vb.label label4 autosize = -1 'true caption = "some kind of way:" Height = 180 left = 120 TabINDEX = 7 TOP = 1200 width = 900 End begin vb.label label3 autosize = - 1 'True Caption = "Total Total:" Height = 180 LEFT = 120 TabINDEX = 4 TOP = 765 Width = 900 End Begin VB.Label Label1 AutoSize = -1 'True Caption = "Strand Number (1-200):" Height = 180 LEFT = 120 TabINDEX = 3 TOP = 330 Width = 1350 End End Begin VB.Frame Frame1 Backcolor = & H80000016 & CAPTION = "Requirements:" Forecolor = & H000000FF & Height = 975 left =
120 TabIndex = 0 Top = 0 Width = 6135 Begin VB.Label Label2 BackColor = & H80000016 & BackStyle = 0 'Transparent Caption = $ "Form1.frx": 0000 ForeColor = & H00FF0000 & Height = 615 Left = 240 TabIndex = 1 Top = 240 Width = 5775 End EndEndAttribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption Explicit 'requirements: a person on the ladder, a total of 100 step, a step may be a cross, one can step across two possible Cross 3 ladders, ask how many ways in the last ladder? Please also list the number of steps per step (according to the order)! DIM A () AS STRINGPRIVATE SUB Command1_Click () DIM STR1 AS STRING IF DSBJ (Text3.Text, A (Combo1.Text)) or text3.text = "" or text3 like "* [! 0-9] *" THEN MSGBOX "Input data is too large or non-numbers", Vbokonly vbexclamation, "step algorithm" text3.setfocus exit sub end if str1 = DGZF (combo1.text, text3.text) text1 = vbnewline & combo1.text & "Level Ladder "& Text3 &"] Talk: "& Vbnewline & str1 & vbnewline & text1end Sub
Private sub combo1_click () text2 = a (combo1.text) text2.tooltiptext = text2nd sub
Private submmand2_click () text1 = "" End Sub
Private sub text2_change () if dsbj (Text3, Text2) or text3 = "" "
'Input data to determine the legality Private Sub Text3_KeyPress (KeyAscii As Integer) Dim str1 As String If KeyAscii = vbKeyRight Or KeyAscii = vbKeyLeft Or KeyAscii = vbKeyBack Then ElseIf KeyAscii
'Sladder Rifting Algorithm Function DGZF (T AS Integer, M AS String) AS Stringdim I as Integer' Regenerated to 1 Order IF T = 1 THEN DGZF = "1" EXIT FUNCTION 'Regeneration to 2nd Order 2nd Elseif T = 2 and m = 2 THEN DGZF = "2" EXIT FUNCTION 'Regeneration to 3th Order 4th Try Elseif T = 3 and M = 4 THEN DGZF = "3" exit function' If the number Small equals ELSEIF NOT (DSBJ (M, A (T - 1))) of the previous order of the previous stage, the DGZF = "1" & DGZF (T - 1, M) ' Total elseif DSBJ (M, A (T - 1)) and not (DSBJ (M, DSYS (A (T - 1), A (T - 2), 1))) The DGZF = "2" & DGZF (T - 2, DSYS (M, A (T - 1), 2)) 'If the number of figures is greater than the total number of ELSEIF DSBJ (M, DSYS (A (T - 1), A (T - 2), 1)) THEN DGZF = "3" & DGZF (T - 3, DSYS (DSYS (M, A (T - 1), 2), A (T - 2), 2)) endix
END FUNCTION
'The total number of ways to take a first order, f (n) = f (n-1) f (n-2) f (n-3) Function ZFZS (n as integer) AS STRING REDIM A (N) DIM I as integer if n> 0 THEN A (1) = 1 IF n> 1 THEN A (2) = 2 IF n> 2 THEN A (3) = 4 for i = 4 to n if LEN (A (i - 1)) <13 THEN A (I) = VAL (A (i - 1)) VAL (A (i - 2)) VAL (A (i - 3)) ELSE A (i) = dsys (DSYS A (I - 1), A (I - 2), 1), A (I - 3), 1) end if next I zfzs = a (n) end function
'High Accuracy Positive Integer Addal and Elevation, That is, the large-scale integer addition and subtraction is' subtraction, known to the first number is mainly used for this program, in order to simplify the code, do not make conversion and symbol judgment, if you want to implement universal Calculate, please adjust the Function DSYS (N1, N2, F) AS String Dim B1 (), B2 (), C, I, and S 'take the large number length segment allocation array size C = IIF (LEN (N1)> LEN (N2), INT (LEN (N1) / 12), INT (LEN (N2) / 12)) 1 REDIM B1 (C 1), B2 (C) S = 0 'N1 Press 12-bit segmentation Deposit in array for i = 1 to LEN (N1) Step 12 s = s 1 if len (n1)> s * 12 THEN B1 (S) = MID (N1, LEN (N1) - S * 12 1, 12 ELSE B1 (S) = MID (N1, 1, LEN (N1) - (S - 1) * 12) End if Next I 'N2 Press 12-bit segmentation to deposit in array s = 0 for i = 1 to LEN (N2) Step 12 S = S 1 IF LEN (N2)> S * 12 THEN B2 (S) = MID (N2, LEN (N2) - S * 12 1, 12) ELSE B2 (S) = MID (N2, 1, LEN (N2) - (S - 1) * 12) End if Next I 'addition IF f = 1 THEN' is added in segment, the result is stored in the array for i = 1 to C B1 (i) = VAL (B1 (i)) VAL (B2 (i)) 'carry if LEN (B1 (i))> 12 THEN B1 (i 1) = VAL (B1 (i 1)) VAL (Left (B1) ( I), LEN (B1 (i)) - 12)) B1 (i) = Right (B1 (i), 12) end IF 'is less than 12 bits 2 dsys = String (12 - len (b1 (i)), "0") & b1 (i) & dsys next I 'subtraction ELSE' is subtracted by segment, the result is stored in the array for i = 1 to C B1 (i) = VAL (B1 (i)) - VAL (B2 (i )) 'Borrow IF B1 (i) <0 THEN B1 (i 1) = VAL (B1 (i 1)) - 1 B1 (i) = VAL (B1 (I)) 10 ^ 12 end if'
Lost 12 位 0 dsys = String (12 - LEN (B1 (i)), "0") & b1 (i) & dsys next i endiff 'going to 0 for i = 1 to Len (DSYS) if MID ( DSYS, I, 1) <> "0" THEN DSYS = MID (DSYS, I) EXIT for End Ind Ind Function '正整 正 数 整 比 (N1 AS String, N2 As String) AS Boolean DSBJ = IIF (LEN (N1)> LEN (N2) or LEN (N1) = LEN (N2) and N1> N2, TRUE, FALSE) END FUNCTION