Last time This time, we will solve the solvable problem of this.
#24 ABC045-C 1110diff
** Thoughts ** For the first time, I learned a method called bit full search, so I will use it. Search all for whether to put a symbol between letters.
s = input()
ans = 0
n = len(s) - 1 #The interval is one less than the number of characters
for i in range(2 ** n):
op = [''] * n
for j in range(n):
if ((i >> j) & 1):
op[n - j - 1] = '+'
formula = ''
for p_n, p_o in zip(s,op+['']):
formula += (p_n+p_o)
ans += eval(formula)
print(ans)
ABC079-C 302diff
** Thoughts ** The difference from the previous problem is that there are two symbols, but they are almost the same. eval calculates a character expression and returns an int.
abcd = input()
n = len(abcd) - 1
for i in range(2 ** n):
op = ['-'] * n
for j in range(n):
if ((i >> j) & 1):
op[n - j - 1] = '+'
formula = ''
for p_n, p_o in zip(abcd, op + ['']):
formula += (p_n + p_o)
if eval(formula) == 7:
print(formula + '=7')
break
ARC029 465diff
** Thoughts ** Search all bits depending on which meat grill you use. After that, just update the minimum value.
n = int(input())
t = [int(input()) for _ in range(n)]
ans = 10**9
for i in range(2 ** n):
niku = ['Left'] * n
for j in range(n):
if ((i >> j) & 1):
niku[n - j - 1] = 'Right'
wait_time_left = 0
wait_time_rignt = 0
for k in range(n):
if niku[k] == 'Left':
wait_time_left += t[k]
if niku[k] == 'Right':
wait_time_rignt += t[k]
wait_time = max(wait_time_left,wait_time_rignt)
ans = min(ans,wait_time)
print(ans)
ABC104-C I couldn't write the processing of the problem to be solved halfway.
d, g = map(int,input().split())
pc = [list(map(int,input().split())) for _ in range(d)]
n = len(pc)
ans = 10**9
for i in range(2 ** n):
cost = 0
score = 0
check = [False] * n
for j in range(n):
if ((i >> j) & 1):
check[n - j - 1] = True
for k in range(n):
if check[k]:
for l in range(pc[k][0]):
cost += 1
score += 100 * (k+1)
if l == pc[k][0]-1:
score += pc[k][1]
if score >= g:
ans = min(ans,cost)
print(ans)
ABC002-C When I was thinking about whether to include 12 members in the faction, I couldn't write a code to confirm each other.
difficult. It's fun to learn new things, but if you can't solve it, it's meaningless, so solve past questions so that you can take root. see you
Recommended Posts