Advertisement
nq1s788

27(3) с двоичными

Jun 19th, 2024
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. data = open('27.txt').readlines()
  2. n = int(data[0])
  3. a = []
  4. for i in range(1, n + 1):
  5.     data[i] = list(map(int, data[i].split()))
  6.     if data[i][1] % 2 == 1:
  7.         a.append(data[i])
  8. n = len(a)
  9. a = list(map(sorted, a))
  10. dp = [[0 for i in range(4)] for j in range(n)]
  11. dp[0][(a[0][0] % 2) * 2 + (a[0][1] % 2)] = sum(a[0])
  12. for i in range(1, n):
  13.     for ost in range(4):
  14.         dp[i][ost] = dp[i - 1][ost]
  15.     x = a[i][0] % 2 #остаток первого в паре
  16.     y = a[i][1] % 2 #остаток второго в паре
  17.     sm = sum(a[i]) #сумма в паре
  18.     for ost in range(4):
  19.         x1 = (ost // 2 + x) % 2
  20.         y1 = (ost % 2 + y) % 2
  21.         dp[i][x1 * 2 + y1] = max(dp[i][x1 * 2 + y1], dp[i - 1][ost] + sm)
  22. print(dp[-1][2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement