import sys
input = sys.stdin.readline
n = int(input())
k = int(input())
cards = [input().rstrip() for _ in range(n)]
dp = [1] * n
res = set()
curStr = ""
def concat(cards, k, n, count):
print(dp)
print(curStr)
if (count == k):
res.add(curStr)
return
for i in range(n):
if dp[i] == 0:
curStr += cards[i]
dp[i] = 1
concat(cards, k, n , count + 1)
dp[i] = 0
curStr = curStr[:-len(cards[i])]
concat(cards, k, n, 0)
print(len(res))
in this code, i can access global variable "dp" without using "global dp" inside function concat, but i cannot do the same to global variable curStr.
so that "print(curStr)" gives me this error : UnboundLocalError: cannot access local variable 'curStr' where it is not associated with a value while print(dp) does not.
I thought I should say "global something" to use any type of global varaible inside function, but in this code, i think this principle is not applied, can you tell me what is the reason??