Advertisement
giGii

no good 7 final B

Jun 13th, 2022
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. def main():
  2.     n = int(input())
  3.     nums = list(map(int, input().split()))
  4.     summary = sum(nums)
  5.     target_summ = summary // 2
  6.     dp = [False for _ in range(target_summ + 1)]
  7.     if target_summ and not summary % 2:
  8.         dp[0] = True
  9.         calc = dp[:]
  10.         sums = list(range(1, target_summ + 1))
  11.         for num in nums:
  12.             for current_summ in sums:
  13.                 if current_summ >= num:
  14.                     calc[current_summ] = dp[current_summ] or dp[current_summ - num]
  15.             dp = calc
  16.     print(dp[-1])
  17.  
  18.  
  19. if __name__ == '__main__':
  20.     main()
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement