Suppose your keyboard, only the following keys: A Ctrl + A Ctrl + C Ctrl + V

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/u013251692/article/details/78025660

Suppose your keyboard, only the following keys:
A
Ctrl + A
Ctrl + C
Ctrl + V
Here Ctrl + A, Ctrl + C, Ctrl + V represent the "Select All", "Copy", "Paste."
If you can only press the keyboard N times, writing a program that can generate the largest number of A.

Thinking analysis, in fact, only need to write the results of the previous button several times that can be generated can analyze the answer:
the key once before without any result was an A, the same way when the button three times will be more than an A, There are currently two a, when only four keys can select all, copy, paste and paste, then a total of 3 a, but may be selected when the five selected when select the 3rd, copy, paste may be selected program select all, copy, paste paste paste, a total of four a, after this, there are two options, ranging from 2 times before the election has been copied and pasted or paste the whole, if you compare the size of two values like the
number - - - - - number of a in
. 1 - - - - - - - -. 1
2 - - - - - - - -. 1
. 3 - - - - - - - - 2
. 4 - - - - - - - -. 3
. 5 - - - - - - - -. 4
. 6 - - - - - - - -. 6
. 7 - - - - - - - -. 8

def get_max_A(times):
    if times==1:           
        return(1)
    if times==2:
        return(1)
    b2=1
    b1=1
    for x in range(3,times+1):
        if b1+1>=b2*2:
            max_a=b1+1
        else:
            max_a=b2*2
        b2=b1
        b1=max_a
        if x==times:
            return(max_a)

A number of times during generation of the previous procedures which 2 b2, b1 representing the current operation frequency, the number of A-1

Guess you like

Origin blog.csdn.net/u013251692/article/details/78025660