Special Keyboard Python

PROGRAM TO PRINT MAXIMUM NUMBER OF A'S USING GIVEN FOUR KEYS



def findoptimal(N):
     
    # The optimal string length is
    # N when N is smaller than
    if N<= 6:
        return N
 
    # Initialize result
    maxi = 0
 
    # TRY ALL POSSIBLE BREAK-POINTS
    # For any keystroke N, we need
    # to loop from N-3 keystrokes
    # back to 1 keystroke to find
    # a breakpoint 'b' after which we
    # will have Ctrl-A, Ctrl-C and then
    # only Ctrl-V all the way.
    for b in range(N-3, 0, -1):
        curr =(N-b-1)*findoptimal(b)
        if curr>maxi:
            maxi = curr
     
    return maxi
# Driver program
if __name__=='__main__':
     
 
# for the rest of the array we will
# rely on the previous
# entries to compute new ones
    for n in range(1, 21):
        print('Maximum Number of As with ', n, 'keystrokes is ', findoptimal(n))


OUTPUT:
Maximum Number of A's with 1 keystrokes is 1
Maximum Number of A's with 2 keystrokes is 2
Maximum Number of A's with 3 keystrokes is 3
Maximum Number of A's with 4 keystrokes is 4
Maximum Number of A's with 5 keystrokes is 5
Maximum Number of A's with 6 keystrokes is 6
Maximum Number of A's with 7 keystrokes is 9
Maximum Number of A's with 8 keystrokes is 12
Maximum Number of A's with 9 keystrokes is 16
Maximum Number of A's with 10 keystrokes is 20
Maximum Number of A's with 11 keystrokes is 27
Maximum Number of A's with 12 keystrokes is 36
Maximum Number of A's with 13 keystrokes is 48
Maximum Number of A's with 14 keystrokes is 64
Maximum Number of A's with 15 keystrokes is 81
Maximum Number of A's with 16 keystrokes is 108
Maximum Number of A's with 17 keystrokes is 144
Maximum Number of A's with 18 keystrokes is 192
Maximum Number of A's with 19 keystrokes is 256
Maximum Number of A's with 20 keystrokes is 324

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java