Problem:


Score : 300 points

Problem Statement

Joisino is planning to open a shop in a shopping street.

Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.

There are already N stores in the street, numbered 1 through N.

You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.

Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.

Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.

Constraints

1≤N≤100

0≤F_{i,j,k}≤1

For every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.

-10^7≤P_{i,j}≤10^7

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
F_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}
:
F_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}
P_{1,0} ... P_{1,10}
:
P_{N,0} ... P_{N,10}

Output

Print the maximum possible profit of Joisino's shop.

Sample Input 1

1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2

Sample Output 1

8

If her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit.

Sample Input 2

2
1 1 1 1 1 0 0 0 0 0
0 0 0 0 0 1 1 1 1 1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1
0 -2 -2 -2 -2 -2 -1 -1 -1 -1 -1

Sample Output 2

-2

Note that a shop must be open during at least one period, and the profit may be negative.

Sample Input 3

3
1 1 1 1 1 1 0 0 1 1
0 1 0 1 1 1 1 0 1 0
1 0 1 1 0 1 0 1 0 1
-8 6 -2 -8 -8 4 8 7 -6 2 2
-9 2 0 1 7 -5 0 -2 -6 5 5
6 -6 7 -9 6 -5 8 0 -9 -7 -7

Sample Output 3

23



Sample input:
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2


Sample output:
8

Submission status: Accepted

Solution code:
N = int(input())
F = []
P = []
for i in range(N):
    f = list(map(int, input().split()))
    F.append(f)
for i in range(N):
    p = list(map(int, input().split()))
    P.append(p)



def solve(K):
    ans = 0
    n = 0
    while n < N:
        num = 0
        for i in range(10):
            if int(K[i]) == F[n][i] and K[i] == '1':
                num = num + 1
        ans += P[n][num]
        n += 1
    return ans
Ans = solve('%010d' % 1)
for m in range(1,1024):
    K = []
    L = int(format(m, 'b'))
    L = '%010d' % L
    k = solve(L)
    Ans = max(Ans, k)
print(Ans)

Submission status: Accepted

Solution code:
def c_shopping_street(N, F, P):
    ans = -float('inf')
    for b in range(1, 1024):  # (2の10乗-1)通り、営業するか否かの選び方がある
        cc = 0  # 利益の暫定値
        for i in range(N):
            c = 0  # 自分と店iとの営業時間が「かぶる」のは何回かを格納
            for j in range(10):
                if ((b >> j) % 2 == 1) and F[i][j] == 1:
                    c += 1
            cc += P[i][c]
        ans = max(ans, cc)  # 利益の最大値を更新
    return ans

N = int(input())
F = [[int(i) for i in input().split()] for j in range(N)]
P = [[int(i) for i in input().split()] for j in range(N)]
print(c_shopping_street(N, F, P))

Submission status: Accepted

Solution code:
import itertools

N = int(input())
Fs = [tuple(map(int, input().split())) for i in range(N)]
Ps = [tuple(map(int, input().split())) for i in range(N)]

ans = -float('inf')
for numOP in range(1, 11):
    for iOPs in itertools.combinations(range(10), numOP):

        profit = 0
        for F, P in zip(Fs, Ps):
            c = sum([F[i] for i in iOPs])
            profit += P[c]
        ans = max(ans, profit)

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    F = [[0] * 10 for _ in range(N)]
    for i in range(N):
        s = input().split()
        for j in range(10):
            F[i][j] = int(s[j])
    P = [[0] * 11 for _ in range(N)]
    for i in range(N):
        s = input().split()
        for j in range(11):
            P[i][j] = int(s[j])

    ans = -INF
    # 2 ^ nの組み合わせの全列挙
    for b in range(1, 2 ** 10):
        o = [0] * 10
        for i in range(10):
            if b & 1 << i:
                o[i] = 1

        total = 0
        for i in range(N):
            c = 0
            for j in range(10):
                if o[j] == 1 and F[i][j] == 1:
                    c += 1
            total += P[i][c]
        ans = max(ans, total)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(raw_input())
lisday = []
lisp= []
last = []
for num in xrange(N):
  lisday.append( map(int,raw_input().split()) )
for num in xrange(N):
  lisp.append( map(int,raw_input().split()) ) 
for n in xrange(1,1024):
	n2 = format(n,"010b")
	lissum =[]
	for numb in xrange(N):
		check = map(int,list(str(n2)))
		count = 0
		for select in xrange(10):
			if check[select] == 1 and lisday[numb][select] == 1:
				count += 1
		lissum.append(lisp[numb][count])
	last.append(sum(lissum))
print max(last)

Submission status: Accepted

Solution code:
from operator import mul

n = int(input())
cof = [1 << x for x in range(10)]
fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]
print(max(sum(p[bin(f & g).count('1')] for f, p in zip(fs, ps)) for g in range(1, 1024)))

Submission status: Accepted

Solution code:
N = int(input())
F = [[] for _ in range(N)]
for i in range(N):
    F[i] = list(map(int, input().split()))
P = [[] for _ in range(N)]
for i in range(N):
    P[i] = list(map(int, input().split()))

joisino = [False] * 10


def dfs(i):
    if i == 10:
        if joisino.count(True) == 0:
            return -float('inf')
        score = 0
        for j in range(N):
            G = [(joisino[k] and (F[j][k] == 1)) for k in range(10)]
            count = G.count(True)
            score += P[j][count]
        return score
    else:
        ans1 = dfs(i + 1)
        joisino[i] = True
        ans2 = dfs(i + 1)
        joisino[i] = False
        return max(ans1, ans2)


ans = max(-float('inf'), dfs(0))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
f = []
p = []
s = [0 for i in range(10)]
for i in range(n):
    f.append(list(int(i) for i in input().split()))
for i in range(n):
    p.append(list(int(i) for i in input().split()))

def count(x):
    cunt = 0
    for i in range(len(openlist)):
        if f[x][9-i] == openlist[len(openlist)-i-1]==1:
            cunt +=1
        #print('cunt = {}'.format(cunt))
    return cunt
max1 = -10000000000000
for i in range(1,1024):
    sum = 0
    open = format(i,'b')
    openlist = [int(j) for j in open]
    #print(openlist)
    for k in range(n):
        sum += p[k][count(k)]
    max1 = max(max1,sum)
print(max1)

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())

F = []
P = []

table = [2**i for i in range(10)]

for i in range(N):
    lis = list(map(int, input().split(' ')))
    F.append(lis)

for i in range(N):
    lis = list(map(int, input().split(' ')))
    P.append(lis)

maxx = -1000000001

for i in range(1, 1024):
    total = 0
    for j in range(N):
        n = 0
        for t in range(10):
            n += (1 if i&table[t] != 0 else 0)*F[j][t]
        total += P[j][n]
    if total > maxx:
        maxx = total

print(maxx)

Submission status: Accepted

Solution code:
from operator import mul

n = int(input())
cof = [1 << x for x in range(10)]
fs = [sum(map(mul, map(int, input().split()), cof)) for _ in range(n)]
ps = [list(map(int, input().split())) for _ in range(n)]
ans = float('-inf')
for g in range(1, 1024):
    ans = max(ans, sum(p[bin(f & g).count('1')] for f, p in zip(fs, ps)))
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
f = [int(''.join(input().split()), 2) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
print(max(
    sum(p[i][sum(map(int, bin(b & f[i])[2:]))] for i in range(n))
    for b in range(1, 2**10)))

Submission status: Accepted

Solution code:
n = int(input())
F = [list(map(int, input().split())) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
res = -(1 << 62)
for ss in range(1, 1 << 10):
    b = [0] * n
    s = ss
    for i in range(5):
        c0 = 1 if s & 1 else 0
        c1 = 1 if s & 2 else 0
        for j in range(n):
            b[j] += F[j][i * 2] * c0 + F[j][i * 2 + 1] * c1
        s >>= 2
    ts = 0
    for i in range(n):
        ts += P[i][b[i]]
    res = max(res, ts)
print(res)

Submission status: Accepted

Solution code:
n = int(input())
f = []
for i in range(n):
  f += [[int(x) for x in input().split()]]
p = []
for i in range(n):
  p += [[int(x) for x in input().split()]]

res = -2100000000
for onechan in range(1, 2 ** 10):
  count = [0 for x in range(n)]
  b = 0
  d = onechan
  for k in range(10):
    if d % 2 == 1:
      for i in range(n):
        if f[i][k] == 1:
          count[i] += 1
    d //= 2

  for i in range(n):
    b += p[i][count[i]]
  res = max(b, res)

print(res)

Submission status: Accepted

Solution code:

import copy

shop_num = int(input().rstrip())

# business hour
shop_data = {}
for i in range(shop_num):
	shop_data[i] = input().rstrip().split(' ')

# benefit
shop_benefit = {}
for i in range(shop_num):
	shop_benefit[i] = input().rstrip().split(' ')

patterns = [0, 1, 2, 3];

targets = []
for pattern1 in patterns:
	list1 = []
	if pattern1 == 1:
		list1.append(0)
	elif pattern1 == 2:
		list1.append(1)
	elif pattern1 == 3:
		list1.append(0)
		list1.append(1)

	for pattern2 in patterns:
		list2 = copy.deepcopy(list1)
		if pattern2 == 1:
			list2.append(2)
		elif pattern2 == 2:
			list2.append(3)
		elif pattern2 == 3:
			list2.append(2)
			list2.append(3)
		for pattern3 in patterns:
			list3 = copy.deepcopy(list2)
			if pattern3 == 1:
				list3.append(4)
			elif pattern3 == 2:
				list3.append(5)
			elif pattern3 == 3:
				list3.append(4)
				list3.append(5)
			for pattern4 in patterns:
				list4 = copy.deepcopy(list3)
				if pattern4 == 1:
					list4.append(6)
				elif pattern4 == 2:
					list4.append(7)
				elif pattern4 == 3:
					list4.append(6)
					list4.append(7)
				for pattern5 in patterns:
					list5 = copy.deepcopy(list4)
					if pattern5 == 1:
						list5.append(8)
					elif pattern5 == 2:
						list5.append(9)
					elif pattern5 == 3:
						list5.append(8)
						list5.append(9)

					targets.append(copy.deepcopy(list5))

ben_list = []
for target in targets:
	if (len(target) <= 0):
		continue;
	ben = 0
	for key in shop_data:
		count = 0
		for time in range(10):
			data = int(shop_data[key][time])
			if time in target:
				if data == 1:
					count += 1

		ben += int(shop_benefit[key][count])

	ben_list.append(ben)

print(max(ben_list))

Submission status: Accepted

Solution code:
#!/usr/bin/python

import sys

def overlap(source, target):
    n = 0
    for s, t in zip(source, target):
        if s == 1 and s == t:
            n += 1
    return n

def main(argv):
    line = sys.stdin.readline()
    while line:
        n = int(line.rstrip("\n"))
        f = []
        for i in xrange(n):
            f.append(map(lambda x: int(x), 
              sys.stdin.readline().rstrip("\n").split(" ")))
        p = []
        for i in xrange(n):
            p.append(map(lambda x: int(x), 
              sys.stdin.readline().rstrip("\n").split(" ")))

        max_profit = -10**7 * n - 1
        for index in xrange(1, 2**10):
            b = map(lambda x: int(x), bin(index)[2:].zfill(10))

            profit = 0
            for i in xrange(n):
                c = overlap(b, f[i])
                profit += p[i][c]

            if profit > max_profit:
                max_profit = profit

        print max_profit

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]

c = [[0] * (2 ** 10) for i in range(N)]
for i in range(N):
    for j in range(2 ** 10):
        for k in range(10):
            if j >> k & 1 == 1 and F[i][k] == 1:
                c[i][j] += 1

s = [0] * (2 ** 10)
for i in range(N):
    for j in range(2 ** 10):
        s[j] += P[i][c[i][j]]

print(max(s[1:]))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
f = []
p = []
for i in range(n):
    f.append(list(map(int, input().split())))
for i in range(n):
    p.append(list(map(int, input().split())))

pattern = []
tmp = []
for i in range(n):
    tmp.append(f[i][0])
pattern.append(tmp)

for i in range(1, 10):
    tmp = []
    tmp_loop = pattern[:]
    for j in range( n):
        tmp.append(f[j][i])
    for pat in tmp_loop:
        pattern.append(list(np.array(pat)+np.array(tmp)))
    pattern.append(tmp)

ans = -100000000000
for pat in pattern:
    a = 0
    for i in range(n):
        a += p[i][pat[i]]
    ans = max(ans, a)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import itertools
def to_bool(i):
    if i == '1':
        return True
    return False

# 整数の入力
n = int(input())
f = []
for i in range(n):
    f.append(list(to_bool(i) for i in input().split()))

p = []
for i in range(n):
    p.append(list(int(i) for i in input().split()))

result = None
for eigyou in itertools.product((True,False), repeat=10):
    if sum(1 for a in eigyou if a) == 0:
        continue
    goukei = None
    for i in range(n):
        if goukei is None:
            goukei = p[i][sum(1 for a,b in zip(eigyou,f[i]) if a and b)]
        else:
            goukei += p[i][sum(1 for a,b in zip(eigyou,f[i]) if a and b)]
    if result is None:
        result = goukei
    if result < goukei:
        result = goukei
    
print(result)

Submission status: Accepted

Solution code:
import itertools
N=input()
F=[]
for i in range(N):
	F.append(map(int,raw_input().split()))
#print F

P=[]
for i in range(N):
	P.append(map(int,raw_input().split()))
#print P


l=list(itertools.product(range(2), repeat=10))
#l=[(1, 1, 1, 1, 1, 0, 0, 0, 0, 0),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1)]
l.remove((0, 0, 0, 0, 0, 0, 0, 0, 0, 0))

b=[[] for i in range(2**10-1)]


for ind_i,i in enumerate(l):
	for j in F:
		#print [min(t) for t in zip(i, j)]
		#print sum([min(t) for t in zip(i, j)])
		b[ind_i].append(sum([min(t) for t in zip(i, j)]))
#print b

b_sum=0
ans=float("-inf")
for ind_i,i in enumerate(b):
	b_sum=0
	for ind_j,j in enumerate(i):
		#print ind_i, ind_j,j
		b_sum+=P[ind_j][j]
	#print sum
	ans=max(ans,b_sum)

print ans

Submission status: Accepted

Solution code:
n = input()
f = [raw_input().split() for _ in xrange(n)]
p = [map(int, raw_input().split()) for _ in xrange(n)]
a = -9999999999L
for _ in xrange(1, 1024):
    cnt, b = 0, '0' * (12 - len(bin(_))) + bin(_)[2:]
    for i, n in enumerate(f):
        ci = 0
        for x in xrange(10):
            if b[x] == n[x] and b[x] == '1':
                ci += 1
        cnt += (p[i][ci])
    a = max(cnt, a)
print a

Submission status: Accepted

Solution code:
n = int(input())
f = []
for _ in range(n):
    f.append(list(map(int, input().split())))
p = []
for _ in range(n):
    p.append(list(map(int, input().split())))
def solve(lst):
    if sum(lst) == 0:
        return -float("inf")
    res = 0
    for i in range(n):
        num = 0
        for j in range(10):
            if lst[j] == 1 and f[i][j] == 1:
                num += 1
        res += p[i][num]
    return res
l = []
for _a in range(2):
        for _b in range(2):
            for _c in range(2):
                for _d in range(2):
                    for _e in range(2):
                        for _f in range(2):
                            for _g in range(2):
                                for _h in range(2):
                                    for _i in range(2):
                                        for _j in range(2):
                                            res = solve([_a, _b, _c, _d, _e, _f, _g, _h, _i, _j])
                                            l.append(res)
print(max(l))

Submission status: Accepted

Solution code:
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
all = [list(format(i,'b').zfill(10)) for i in range(1,1025)]
ans = -100000000000000000000000

for i in range(1024):
    cnt = []
    gokei = 0
    for j in range(N):

        z = 0
        for a,b in zip(all[i],F[j]):
            if int(a)+b==2:
                z += 1
        cnt.append(z)
    for m in range(N):
        gokei += P[m][cnt[m]]

    ans = max(ans, gokei)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
f = np.zeros((n, 10))
p = np.zeros((n, 11))
for i in range(n):
    f[i] = np.array(list(map(int, input().split())))

for i in range(n):
    p[i] = np.array(list(map(int, input().split())))

l = 10
f_n = 2**l-1
ans = (-10**7)*10*n
for i in range(2**l-1):
    ff = np.array(list(map(int,list(format(f_n,'b').zfill(l)))))
    c = np.sum(ff*f, dtype=np.int64, axis=1)
    c = np.eye(11)[c]
    tmp = np.sum(c*p)
    if ans < tmp:
        ans = tmp
    f_n -= 1
    
print (int(ans))

Submission status: Accepted

Solution code:
n=int(input())

ans=-10**9
f=[[0 for i in range(10)] for j in range(n)]
p=[[0 for i in range(11)] for j in range(n)]

for i in range(n):
  f[i]=[int(i) for i in input().split()]
for i in range(n):
  p[i]=[int(i) for i in input().split()]


for i1 in range(2):
  for i2 in range(2):
    for i3 in range(2):
      for i4 in range(2):
        for i5 in range(2):
          for i6 in range(2):
            for i7 in range(2):
              for i8 in range(2):
                for i9 in range(2):
                  for i10 in range(2):
                    sumi=i1+i2+i3+i4+i5+i6+i7+i8+i9+i10
                    count=[0 for i in range(n)]
                    for ii in range(n):
                        if i1==f[ii][0] and i1==1:
                          count[ii]=count[ii]+1
                        if i2==f[ii][1] and i2==1:
                          count[ii]=count[ii]+1
                        if i3==f[ii][2] and i3==1:
                          count[ii]=count[ii]+1
                        if i4==f[ii][3] and i4==1:
                          count[ii]=count[ii]+1   
                        if i5==f[ii][4] and i5==1:
                          count[ii]=count[ii]+1
                        if i6==f[ii][5] and i6==1:
                          count[ii]=count[ii]+1
                        if i7==f[ii][6] and i7==1:
                          count[ii]=count[ii]+1
                        if i8==f[ii][7] and i8==1:
                          count[ii]=count[ii]+1
                        if i9==f[ii][8] and i9==1:
                          count[ii]=count[ii]+1   
                        if i10==f[ii][9] and i10==1:
                          count[ii]=count[ii]+1                          
                    
                    if sumi>0:
                      ans_0=0
                      #print(count)
                      for i in range(n):
                         ans_0=ans_0+p[i][count[i]]
                      ans=max(ans,ans_0)
                          
                                                                            
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())
F = [input().split(" ") for _ in range(N)]
P = [input().split(" ") for _ in range(N)]

max_res = 0

for i,j in enumerate(product("01",repeat=10)):
    if i != 0:
        res = [0 for _ in range(N)]
        for k, flag in enumerate(j):
            if flag == "1":
                for l,f in enumerate(F):
                    if f[k] == "1":
                        res[l] += 1
        buf = 0
        for m in range(N):
            buf += int(P[m][res[m]])
        if i==1:
            max_res = buf
        else:
            max_res = max(buf,max_res)

print(max_res)

Submission status: Accepted

Solution code:
import copy

N=int(input())
F=[ [ [ 0 for i in range(3)] for j in range(6)] for k in range(N+1)]
# print(F)
for i in range(1,N+1):
     line = [int(k) for k in input().split()]
     for j in range(1,6):
         for k in range(1,3):
             F[i][j][k]=line[2*(j-1)+(k-1)]

P=[[0 for i in range(11)] for j in range(N+1)]
for i in range(1,N+1):
    line = [int(j) for j in input().split()]
    for k in range(11):
        P[i][k]=line[k]

# print(P)
# print(F)

stack=[]
stack.append([True])
stack.append([False])
rieki_max=float("inf")
# print(stack)
while(1):
    if len(stack)==0:
        break
    kumiawase=stack.pop()
    if len(kumiawase)==10:
        #利益計算
        if kumiawase.count(True)==0:
            continue
        kaburi=[0 for i in range(N+1)]
        for i in range(1,6):
            for j in range(1,3):
                if kumiawase[(i-1)*2+j-1]==False:
                    continue
                for k in range(1,N+1):
                    if F[k][i][j]==1:
                        kaburi[k]+=1
        rieki=0
        # print(kaburi)
        for i in range(0,N+1):
            rieki+=P[i][kaburi[i]]
        # print(kumiawase,kaburi,rieki)
        if rieki_max < rieki or rieki_max==float("inf"):
            rieki_max = rieki
    else:
        tmp_a = copy.deepcopy(kumiawase)
        tmp_a.append(True)
        stack.append(tmp_a)
        tmp_b = copy.deepcopy(kumiawase)
        tmp_b.append(False)
        stack.append(tmp_b)
print(rieki_max)

Submission status: Accepted

Solution code:
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]

benefits = -1000000000

for t in range(1,1024):
  bits = list(bin(t))
  a = [0 for _ in range(n)]
  jk = 0
  while jk < 10:
    b = bits.pop()
    if b == "b":
      break
    elif b == "0":
      jk += 1
      continue
    else:
      for i in range(n):
        if f[i][jk]:
          a[i] += 1
      jk += 1
  
  s = 0
  for i in range(n):
    s += p[i][a[i]]
  else:
    benefits = max(s,benefits)
else:
  print(benefits)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""abc080_c"""


import sys


def numFromBitList(l):
    """Get number from bit list."""
    n = 0
    for i, v in enumerate(l):
        n += v * 2 ** i
    return n

def main():
    """Main function."""
    n = int(input())

    fs = []
    for _ in range(n):
        fs.append(numFromBitList(list(map(int, input().split(' ')))))

    ps = []
    for _ in range(n):
        ps.append(list(map(int, input().split(' '))))

    max_ = -sys.maxsize
    for i in range(1, 1024):
        profit = 0
        for idx, f in enumerate(fs):
            profit += ps[idx][bin(i & f)[2:].count('1')]
        max_ = max(max_, profit)

    print(max_)


if __name__ == '__main__':
    sys.exit(main())

Submission status: Accepted

Solution code:
N = int(input())
a = []
b = []
total_profit = []
for i in range(N):
    a.append(list(map(int, input().split())))
for j in range(N):
    b.append(list(map(int, input().split())))

for k in range(2, 2 ** 10):
    d = bin(k)
    e = "0" * (12 - len(d)) + d[2:]
    profit = 0
    for l in range(N):
        common_open = 0
        for m in range(10):
            if a[l][m] == 1 and int(e[m]) == 1:
                common_open = common_open + 1
        profit = profit + b[l][common_open]
    total_profit.append(profit)

print(max(total_profit))

Submission status: Accepted

Solution code:
N = int(raw_input())
F = []
for i in range(N):
    li = map(int,raw_input().split())
    F.append(li)
P = []
for i in range(N):
    li = map(int,raw_input().split())
    P.append(li)
bigest = None
for i in range(1024):
    kasa = []
    for x in range(N):
        kasa.append(0)
    i = i + 1 
    bi = str(bin(i)).split("b")[1]
    bi = (10-len(bi))*"0" + bi
    for i2 in range(10):
        if bi[i2]  == "1":
            for i3 in range(N):
                if F[i3][i2] == 1:
                    kasa[i3] += 1
    me = 0 
    for i2 in range(N):
        me += P[i2][kasa[i2]]
    if bigest < me or bigest == None:
        bigest = me
print bigest

Submission status: Accepted

Solution code:
n = int(input())
f = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]

ans = -1234567890
for mask in range(1,2**10):
    tmp = 0
    for i in range(n):
        cnt = 0
        for x in range(10):
            if (mask>>x) % 2 == 1 and f[i][x] == 1: cnt += 1
        tmp += p[i][cnt]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

import numpy as np

n = raw_input()
n = int(n)
f = np.zeros([n,10],int)
for i in range(n):
    line = raw_input()
    line = line.split()
    line = map(int,line)
    f[i] = line
p = np.zeros([n,11],int)
for i in range(n):
    line = raw_input()
    line = line.split()
    line = map(int,line)
    p[i] = line

for i in range(2**10):
    kaburi = np.zeros([n],int)
    num = i
    for j in range(10):
        shutten = num % 2
        num = num / 2
        if shutten == 1:
            for k in range(n):
                if f[k,j] == 1:
                    kaburi[k] += 1
    rieki = 0
    for k in range(n):
        rieki += p[k][kaburi[k]]
    if i <= 1:
        saidai = rieki
    else:
        saidai = max(rieki,saidai)

print saidai

Submission status: Accepted

Solution code:
import sys
import numpy as np
import itertools as it

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

n = I()
F, P = [], []
for _ in range(n):
    F.append(LI())

for _ in range(n):
    P.append(LI())

F = np.array(F)

b = (0, 1)
b10 = (b,)*10
iter_ = it.product(*b10)

Fdotx = [F.dot(x) for x in iter_][1:]

print(max([sum([P[i][val] for i, val in enumerate(row)]) for row in Fdotx]))

Submission status: Accepted

Solution code:
N = int(input())

F = []
for i in range(N):
    F.append(list(map(int, input().split(' '))))

P = []
for i in range(N):
    P.append(list(map(int, input().split(' '))))

max_ = -1000000000

for i in range(1, 2 ** 10):
    pattern = [int((i >> _i) % 2 == 1) for _i in range(10)]
    
    score = 0
    for n in range(N):
        same_num = 0
        for j in range(10):
            if pattern[j] == 0:
                continue
            if F[n][j] == 1:
                same_num += 1
        score += P[n][same_num]
    if score > max_:
        max_ = score
print(max_)

Submission status: Accepted

Solution code:
import itertools

if __name__ == '__main__':
    N = int(input())
    F = [list(map(int, input().split())) for _ in range(N)]
    P = [list(map(int, input().split())) for _ in range(N)]

    # print(list(itertools.product(range(2), repeat=10)))

    max1 = -float('inf')
    max2 = -float('inf')

    for target in list(itertools.product(range(2), repeat=10)):
        sum_every_shop = 0
        for i in range(N):
            sum_same_time = 0
            for j in range(10):
                if target[j] == 1 and F[i][j] == 1:
                    sum_same_time += 1

            sum_every_shop += P[i][sum_same_time]

        if max2 < sum_every_shop:
            max2 = sum_every_shop

        if max1 < max2:
            max1, max2 = max2, max1
            result_target = target

    if result_target == (0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
        print(max2)
    else:
        print(max1)

Submission status: Accepted

Solution code:
import sys
import math

N = int(input())
F = []
for i in range(N):
    F.append(list(map(int, input().split(' '))))
P = []
for i in range(N):
    P.append(list(map(int, input().split(' '))))
maxprofit = None 
for i in range(1, 1024):
    binstr = bin(i) 
    original = list(map(int, binstr[2:]))
    original = [0]*(10-len(original)) + original
    profit = 0
    for j in range(N):
        s = [a+b for (a, b) in zip(original, F[j])]
        dup = len([a for a in s if a == 2])
        profit += P[j][dup]
    if not maxprofit or maxprofit < profit:
        maxprofit = profit
print(maxprofit)

Submission status: Accepted

Solution code:
n=int(input())
num=[]
for _ in range(n):
    s=input()
    s=s.replace(" ","")
    #print(s)
    num.append(int(s,2))
    #print(num)
p=[]
for _ in range(n):
    l=[int(x) for x in input().split()]
    p.append(l)
ans=-10**20
for i in range(1,1024):
    tot=0
    ind=0
    for ele in num:
        var=ele&i 
        tot+=p[ind][bin(var).count('1')]
        ind+=1 
    ans=max(ans,tot)
print(ans)

Submission status: Accepted

Solution code:
import sys

line = sys.stdin.readline()
N = int(line.strip())

F = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        F[i, j] = xs[j]

f = [sum((1 << j) for j in range(10) if F[i,j]) for i in range(N)]

pt = [sum(((i >> j) & 1) for j in range(10)) for i in range(2**10)]

P = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(11):
        P[i, j] = xs[j]


rr = -100000000000000000000

for i in range(1, 2**10):
    r = sum([P[j, pt[f[j] & i]] for j in range(N)])
    if rr < r:
        rr = r

print(rr)

Submission status: Accepted

Solution code:
N = int(input())
F = []
for i in range(N):
    F.append(list(map(int, input().split())))
P = []
for i in range(N):
    P.append(list(map(int, input().split())))

result = -float("inf")
    
for i in range(2 ** 10):
    if i != 0:
        op = list(bin(i)[2:].zfill(10))
        profit = 0
        for n in range(N):
            num = 0
            for j in range(10):
                if str(F[n][j]) == op[j] == "1":
                    num += 1
            profit += P[n][num]
        if i == 2 or result < profit:
            result = profit
print(result)

Submission status: Accepted

Solution code:
# your code goes here
from itertools import product
def inpl(): return map(int, input().split())

N = int(input())
F = [tuple(inpl()) for _ in range(N)]
P = [tuple(inpl()) for _ in range(N)]

result = -1 * 10**12
for T in product([0, 1], repeat=10):
    if sum(T) == 0:
        continue
    tmp = 0
    for i in range(N):
        c = sum([f*t for f, t in zip(F[i], T)])
        tmp += P[i][c]
    result = max(result, tmp)
print(result)