-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3-wjdheesp44 #10
3-wjdheesp44 #10
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν¬μλμ΄λ μκ°ν λ‘μ§ μ체λ λΉμ·νλλ°, μ κ° νΌ μ½λλ ν λ² μ¬λ €λ΄μ©
κΈ°λ³Έμ μΈ μ½λ ꡬ쑰λ λκ°μλ°, κ° μ°μ°μλ§λ€ μ€νν΄μ£Όμ΄μΌλλ? μ½λκ° ν μ€λ‘ μμμ€λμ΄μμ΄μ μ‘°κΈ λ μ§κ΄μ μΈ κ² κ°λ€λ μκ°λ λλ€μ μ΄μ¨λ μκ³ νμ
¨μ΅λλ€ !!
'''logic
1. dfsλ₯Ό μ΄μ©ν μ΅λμ΅μλ₯Ό ꡬνλ λ°©λ²'''
import sys
input = sys.stdin.readline
num = int(input())
num_list = list(map(int, input().split()))
# μ°μ°μ
op = list(map(int, input().split()))
# μ΅μκ° μ΅λκ° μ΄κΈ°ν !
max_num = -1e9
min_num = 1e9
# dfs λ©μλ ꡬν
def dfs(depth, total, add, sub, mul, div):
global max_num, min_num
if depth == num:
max_num = max(total, max_num)
min_num = min(total, min_num)
return
if add:
dfs(depth +1, total + num_list[depth], add-1, sub, mul, div)
if sub:
dfs(depth+1, total - num_list[depth], add, sub-1, mul, div)
if mul:
dfs(depth+1, total * num_list[depth], add, sub, mul-1, div)
if div:
dfs(depth+1, int(total/num_list[depth]), add, sub, mul, div-1)
dfs(1, num_list[0], op[0], op[1], op[2], op[3])
print(max_num)
print(min_num)
def backtracking(i, total): | ||
global add, sub, mul, div, max_value, min_value | ||
if i == n: | ||
max_value = max(max_value, total) | ||
min_value = min(min_value, total) | ||
return | ||
|
||
if add > 0: | ||
add -= 1 | ||
backtracking(i+1, total + nums[i]) | ||
add += 1 | ||
if sub > 0: | ||
sub -= 1 | ||
backtracking(i+1, total - nums[i]) | ||
sub += 1 | ||
if mul > 0: | ||
mul -= 1 | ||
backtracking(i+1, total * nums[i]) | ||
mul += 1 | ||
if div > 0: | ||
div -= 1 | ||
backtracking(i+1, int(total / nums[i])) | ||
div += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ λ μμ μ νμ΄μ¬μΌλ‘ νμμλλ°, μ λ ν΄λΉ μ½λλ₯Ό μ΄λ κ² μμ±νμμ΄μ!
def dfs(depth, total, add, sub, mul, div):
global max_num, min_num
if depth == num:
max_num = max(total, max_num)
min_num = min(total, min_num)
return
if add:
dfs(depth +1, total + num_list[depth], add-1, sub, mul, div)
if sub:
dfs(depth+1, total - num_list[depth], add, sub-1, mul, div)
if mul:
dfs(depth+1, total * num_list[depth], add, sub, mul-1, div)
if div:
dfs(depth+1, int(total/num_list[depth]), add, sub, mul, div-1)
mul += 1 | ||
if div > 0: | ||
div -= 1 | ||
backtracking(i+1, int(total / nums[i])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int(total / nums[i])
total // nums[i]
μλμ²λΌ μ μ λλμ
μ°μ°μ("//")λ₯Ό μ¨μ κ²°κ³Όλ₯Ό λ΄λ¦Όν μ λ μλ€μ μ²μ μμμ΅λλ€ γ
γ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λλΆμ λ°±νΈλ νΉ μκ³ λ¦¬μ¦ μ°Ύμ보면μ 곡λΆνμ΅λλ€.
π λ¬Έμ λ§ν¬
14888λ² μ°μ°μ λΌμλ£κΈ°
βοΈ μμλ μκ°
40λΆ
β¨ μλ μ½λ
λ°±νΈλνΉ, λΈλ£¨νΈν¬μ€λ₯Ό μ΄μ©νλ λ¬Έμ μμ΅λλ€.
κ³ λ €ν μ
μμ
π μλ‘κ² μκ²λ λ΄μ©
μ²μμ μμ κ²°κ³Όμ μ΅λκ°κ³Ό μ΅μκ°μ λ²μμ λλμ μ°μ° λ°©λ²μ μ λλ‘ λ³΄μ§ μμμ κ³μ κ°μ΄ λ€λ₯΄κ² λμμ΅λλ€. νμ΄μ¬μμλ λλμ μ°μ° λ°©λ²μ΄ λ€λ₯΄λ€λ κ²μ μκ² λ κ² κ°μμ.