'What storage method 2 use 4 saving and deleting .txt files programmatically on specific external storage, and loading .txt files on android 11?

I looked up scoped storage but that won't work because of the permission request seeing my apps feature has to delete files on backpress (if user changes folder name)/ onstop, and also multiple .txt files need to be loaded when user restores/backsup notes.

Media store doesnt say anything about .txt files nor about deleting them, that i could find. And it cant be public storage(documents or downloads) because it also writes to folder name that user types. Any help would be great, currently app is rejected from using manage_external_storage. It seems like manage external storage is the only way to go. Thanks

this is my current code

  FileUtil.writeFile(FileUtil.getExternalStorageDir().
  concat("/Folder/text.txt"), e2.getText().toString());

  FileUtil.deleteFile(FileUtil.getExternalStorageDir().
  concat("/Folder/text.txt"));


Solution 1:[1]

The code is essentially the same as the recursive formula, except you compute the function for every possible value of n and k (up to limits) and store results in an appropriately sized array (table). You have to be careful not to access the table out of bounds.

Here's a solution in Python, optimized for readability rather that maximum efficiency.

def countstep(N, K):
    table = [[None] * (K+1) for _ in range(N+1)]
    for k in range(K+1):
        table[0][k] = 1
    for n in range(1, N+1):
        for k in range(K+1):
            t = 0
            if n >= 1:
                t += table[n-1][k]
            if n >= 2:
                t += table[n-2][k]
            if n >= 3 and k > 0:
                t += table[n-3][k-1]
            table[n][k] = t
    return table[N][K]

You can, with some care, make the table 4 by K+1 rather than N+1 by K+1, since at every point, you're only interested in the table entries for the last 4 values of N. Here's a version that does this (note that it uses the python feature that accessing an array with a negative index returns an element from the end of the list (eg: table[-2] is the next-to-last row of table)).

def countstep(N, K):
    table = [[None] * (K+1) for _ in range(4)]
    for k in range(K+1):
        table[0][k] = 1
    for n in range(1, N+1):
        for k in range(K+1):
            ti = n % 4
            t = 0
            if n >= 1:
                t += table[ti-1][k]
            if n >= 2:
                t += table[ti-2][k]
            if n >= 3 and k > 0:
                t += table[ti-3][k-1]
            table[ti][k] = t
    return table[N%4][K]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paul Hankin