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:
#from collections import Counter
N=int(input())
F=list(list(map(int,input().split())) for i in range(N))
P=list(list(map(int,input().split())) for i in range(N))
ans=-(1<<40)
for bit in range(1,1<<10):
    tmp = 0
    for i in range(N):
        c=0
        for j in range(10):
            if bit&(1<<j) and F[i][j]:
                c+=1
        tmp+=P[i][c]
    ans = max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

import numpy as np

n = int(input())
f = []
p = []

for i in range(n):
    f.append(np.array([int(i) for i in input().split()]))

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

#######################

max_score = -1e10

for my_shop_count in range(1, 11, 1): #いくつ店を出すか、1から10までのcombination
    for comb in combinations(np.arange(10), my_shop_count):
        score = 0
        for shop_index in range(n):
            order = 0
            for j in range(my_shop_count):
                order += f[shop_index][comb[j]]
            score += p[shop_index][order]

        if(score > max_score):
            max_score = score

print(max_score)

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 = -float('inf')
for i in range(1,1<<10):
    cnt = [0 for _ in range(n)]
    for j in range(10):
        for k in range(n):
            if (i>>j)&1 and f[k][10-j-1]:
                cnt[k] += 1
    total = 0
    for k in range(n):
        total += p[k][cnt[k]]
    res = max(res,total)
print(res)

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 = -10 ** 11
for i in range(1, 2**10) :
    ans1 = 0
    t = format(i, "010b")
    for j in range(n) :
        kaburi = 0
        for k in range(10) :
            #print(t)
            if int(t[k]) * F[j][k] == 1 :
                kaburi += 1
        ans1 += P[j][kaburi]
    #print("{} {}".format(t,ans1))
    #if ans1>ans :
    #    print(t)
    ans = max(ans, ans1)

print(ans)

Submission status: Accepted

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

ans = -float('inf')
for i in range(1, 2 ** 10):
    A = []
    while i > 0:
        A.append(i % 2)
        i //= 2
    while len(A) < 10:
        A.append(0)
        
    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if F[j][k] == 1 and A[k] == 1:
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans, tmp)
    
print(ans)

Submission status: Accepted

Solution code:
#ABC080C
N=int(input())
F=[]
P=[]
for n in range(N):
	F.append(list(map(int,input().split())))
for n in range(N):
	P.append(list(map(int,input().split())))
def DP(a,i):
	if i!=10:
		ans=max(DP(a+[1],i+1),DP(a+[0],i+1))
	elif any(a):
		ans=0
		for n in range(N):
			c=0
			for i in range(10):
				if F[n][i] and a[i]:
					c+=1
			ans+=P[n][c]
	else:
		ans=-float('inf')
	return ans
print(DP([],0))

Submission status: Accepted

Solution code:
import itertools

N = int(input())

Flist = []
for i in range(N):
    f = [int(x) for x in input().split()]
    Flist.append(f)

Plist = []
for i in range(N):
    p = [int(x) for x in input().split()]
    Plist.append(p)

cases = []
for i in range(1,11):
    cases.extend(list(itertools.combinations([0,1,2,3,4,5,6,7,8,9], i)))

result = -10**9
for case in cases:
    counter = [0]*N
    cache = 0
    for x in case:
        for i,f in enumerate(Flist):
            if f[x] == 1:
                counter[i] += 1
    for i,count in enumerate(counter):
        cache += Plist[i][count]
    if cache > result:
        result = cache

print(result)

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)]

def score(_bin, F, P):
    score = 0
    for j, f in enumerate(F):
        hit_counter = 0
        for i in range(10):
            if _bin>>i & 1 and f[i] == 1:
                hit_counter += 1
        score += P[j][hit_counter]
    return score

max_score = -1<<30
for i in range(1,1<<10):
    max_score = max(max_score, score(i, F, P))

print(max_score)

Submission status: Accepted

Solution code:
n = int(input())

stores = [list(map(int, input().split())) for x in range(n)]
p = [list(map(int, input().split())) for x in range(n)]


best_value = -float("inf")
for flg in range(1, 2**10):
    bit = [(flg >> v) & 1 for v in range(10)]
    c = [0 for x in range(n)]
    for i in range(n):
        for v1, v2 in zip(bit, stores[i]):
            if v1 == v2 == 1:
                c[i] += 1
    benefit = 0
    for i, c_value in enumerate(c):
        benefit += p[i][c_value]
    best_value = max(best_value, benefit)
print(best_value)

Submission status: Accepted

Solution code:
N=int(input())
F=[[0]*10 for _ in range(N)]
P=[[0]*11 for _ in range(N)]
for i in range(N):
    F[i]=list(map(int,input().split()))
for i in range(N):
    P[i]=list(map(int,input().split()))
i=1
ans=int(-10e15)
cnt=0
while i<=int('1111111111',2):
    tmp_ans=0
    bin_str=format(i,'10b')
    for j in range(N):
        cnt=0
        for k in range(10):
            if bin_str[k]=='1' and F[j][k]==1:
                cnt+=1
        tmp_ans+=P[j][cnt]
    if tmp_ans>ans:
        ans=tmp_ans
    i+=1
print(ans)

Submission status: Accepted

Solution code:
I=input;n=int(I());f=[int(I()[::2],2)for _ in[0]*n];p=[I().split()for _ in[0]*n];print(max(sum(int(q[bin(i&g).count('1')])for g,q in zip(f,p))for i in range(1,1024)))

Submission status: Accepted

Solution code:
I=input;n=int(I());f=[int(I()[::2],2)for _ in[0]*n];p=[list(map(int,I().split()))for _ in[0]*n];print(max(sum(q[bin(i&g).count('1')]for g,q in zip(f,p))for i in range(1,1024)))

Submission status: Accepted

Solution code:
import itertools

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 =int(-10e15)
for k in range(1,11):
  for j in itertools.combinations(range(10),k):
    tmp = 0
    for f,p in zip(F, P):
      num = sum([f[cnt] for cnt in j])
      tmp += p[num]
    ans = max(ans,tmp)
    
print(ans)

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())))
  
ma = -10e10

for i in range(1, 1024):
  t = i
  x = []
  for j in range(10):
    x.append(t % 2)
    t //= 2
  wa = 0
  for j in range(N):
    cnt = 0
    for k in range(10):
      if x[k] == 1 and F[j][k] == 1:
        cnt += 1
    wa += P[j][cnt]
    
  if ma < wa:
    ma = wa
print(ma)

Submission status: Accepted

Solution code:
n=int(input())
f=[list(map(str,input().split()))for i in range(n)]
p=[list(map(int,input().split()))for i in range(n)]
d=[]
for i in range(n):
    c=""
    for j in range(10):
        c+=f[i][j]
    else:
        d.append(int(c,2))
ans=float("-inf")
for i in range(1,1024):
    k=0
    for j in range(n):
        k+=p[j][bin(d[j]&i).count("1")] 
    else:
        ans=max(k,ans)
print(ans)

Submission status: Accepted

Solution code:
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getint():
    return int(input())
def getints():
    return [int(i) for i in input().split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
f = getintslines(n)
p = getintslines(n)

# すべての営業パターンについて、全探索(1024通りなので全体で10^5オーダーであり間に合う)
# |profit| <= NP_{i,j}なので絶対値はたかだか10^9
profit = -10**10

for sale in range(1,1025):
    shops = [0]*n
    pattern = format(sale, '010b')
    for i, time in enumerate(pattern):
        if time == '1':
            for j in range(n):
                shops[j] += f[j][i]
    tmp = 0
    for i, s in enumerate(shops):
        tmp += p[i][s]
    profit = max(tmp, profit)
    
print(profit)

Submission status: Accepted

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

ans = -(10**9+7)
for i in range(1, 2**10):
  tmp = 0
  for f, p in zip(F, P):
    tmp += p[bin(f&i).count('1')]
  ans = max(ans, tmp)
print(ans)

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 = -float("inf")
for bit in range(1, 1 << 10):
    cc = 0
    for i in range(n):
        c = 0
        for j in range(10):
            if (bit >> j & 1) and f[i][j]:
                c += 1
        cc += p[i][c]
    ans = max(ans, cc)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
f, p = [], []
scores = []
for i in range(n):
    f.append(int(int("".join(list(input().split())), 2)))
for i in range(n):
    p.append(list(map(int,input().split())))
for i in range(1,1024):
    score = 0
    for j in range(n):
        double = bin(i & f[j]).count("1")
        score += p[j][double]
    scores.append(score)
print(max(scores))

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)]
ans=-float('inf')
for i in range(1,1<<10):
    OPEN=[0]*n
    for j in range(10):
        if (i>>j)&1:
            for k in range(n):
                if F[k][j]==1:
                    OPEN[k]+=1
    tmp=0
    for l in range(n):
        tmp+=P[l][OPEN[l]]
    ans=max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
import itertools
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)]
b = [0,1]
ans = -float('inf')
for e in itertools.product(b,repeat=10):
    e = list(e)
    if e == [0]*10:
        continue
    res = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if e[j] == 1 and F[i][j] == 1:
                cnt += 1
        res += P[i][cnt]
    if res > ans:
        ans = res
print(ans)

Submission status: Accepted

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

ans = -(10**9+7)
for i in range(1, 2**10):
  tmp = 0
  for f, p in zip(F, P):
    tmp += p[bin(f&i).count('1')]
  ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F = [ int(input().replace(" ", ""), 2) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = - 10**10

for i in range(1,1<<10):
    ans = max(ans, sum(P[n][bin(i&F[n]).count('1')] for n in range(N)))
print(ans)

Submission status: Accepted

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = - 10**10

for i in range(1,1<<10):
    score = 0
    for n in range(N):
        f = "".join(map(str,F[n])) 
        b = "{:010b}".format(i)
        c = [int(f[i]) & int(b[i]) for i in range(10)]
        cnt = len(list(filter( lambda x: x, c)))
        score += P[n][cnt]
    ans = max(ans, score)
print(ans)

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)]
from itertools import product
gain=[]
for p in product([0,1,2,3],repeat=5):
    C=[0 for i in range(N)]
    for i in range(5):
        for j in range(N):
            am=F[j][2*i]
            pm=F[j][2*i+1]
            if p[i]==1:
                C[j]+=am
            elif p[i]==2:
                C[j]+=pm
            elif p[i]==3:
                C[j]+=am+pm
    g=0
    for j in range(N):
        g+=P[j][C[j]]
    
    flag=False
    for i in range(5):
        if p[i]!=0:
            flag=True
    if flag:
        gain.append(g)

print(max(gain))

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)]

ans = -float('inf')
for k in range(1, 2**10):
    *bi, = map(int, bin(k).zfill(10).replace('b', '0')[::-1])
    ans = max(ans, sum([p[i][[bi[j] & f[i][j] for j in range(10)].count(1)]
              for i in range(n)]))
print(ans)

Submission status: Accepted

Solution code:
def solve(N, Fs, Ps):
    profit = - 10 ** 10
    for k in range(1, 1025):
        b = "{:010b}".format(k)
        p = 0
        for P, F in zip(Ps, Fs):
           p += P[sum(F[i] * int(b[i]) for i in range(10))]
        profit = max(profit, p)
    return profit

if __name__ == "__main__":
    N = int(input())
    Fs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    Ps = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(solve(N, Fs, Ps))

Submission status: Accepted

Solution code:
# C
N = int(input())
F = []
for _ in range(N):
    f = "".join(list(input().split()))
    F.append(int(f, 2))

P = []
for _ in range(N):
    P.append(list(map(int, input().split())))
    
ans = - float('inf')
for n in range(1, 1<<10):
    cur = 0
    for mise in range(N):
        mise_open = F[mise]
        both_open_cnt = bin(mise_open&n).count("1")
        cur += P[mise][both_open_cnt]
    ans = max(cur, ans)
print(ans)

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())))

ans = -999999999999999999
for i in range(1 << 10):
    A = [0] * N

    cnt = 0
    for j in range(10):
        if (i >> j) & 1:
            cnt += 1
            for k in range(N):
                if F[k][j] == 1:
                    A[k] += 1
    if cnt == 0:
        continue
    tmp = 0
    for t in range(N):
        tmp += P[t][A[t]]

    if tmp > ans:
        ans = tmp
print(ans)

Submission status: Accepted

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

from itertools import product
ans = -float('inf')
for jo in product(range(2), repeat=10):
    if sum(jo) == 0:
        continue
    prof = 0
    for p, f in zip(ps, fs):
        sim = sum(i * j for i, j in zip(jo, f))
        prof += p[sim]
    if prof > ans:
        ans = prof

print(ans)

Submission status: Accepted

Solution code:
def binaryarray_to_int(a):
    res = 0
    for x in a:
        res = (res << 1) + x
    return res

def count_bits(x):
    res = 0
    while x > 0:
        res += (x & 1)
        x = x >> 1
    return res


def solve():
    N = int(input())

    F = [
        binaryarray_to_int(
            [int(x) for x in input().split()]
        )
        for _ in range(N)
    ]

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

    # simulate all patterns
    ans = -float("inf")
    for mask in range(1, 1024):
        p = 0
        for i in range(N):
            bit = mask & F[i]
            c = count_bits(bit)
            p += P[i][c]
        ans = max(ans, p)

    return ans


print(solve())

Submission status: Accepted

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

ans = -float("inf")
for bit in range(1 << 10) :
    expl = []
    for k in range(10) :
        if bit & (1 << k) :
            expl.append(k)
    if len(expl) :
        benefit = 0
        for i in range(N) :
            cnt = 0
            for j in range(len(expl)) :
                if F[i][expl[j]] :
                    cnt += 1
            benefit += P[i][cnt]
        if ans < benefit :
            ans = benefit
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

from itertools import product

def main():
    n = int(input())
    f = []
    p = []
    for ob in (f, p):
        for i in range(n):
            ro = list(map(int, input().split()))
            ob.append(ro)
    res = -99999999999
    for open_at in product((0, 1), repeat=10):
        if 1 not in open_at:
            continue
        res = max(res, get_rieki(f, p, open_at, n))
    print(res)

def get_rieki(f, p, open_at, n):
    res = 0
    for i in range(n):
        cnt = sum(f[i][t] * open_at[t] for t in range(10))
        res += p[i][cnt]
    return res

main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

from itertools import product

def main():
    n = int(input())
    f = []
    p = []
    for ob in (f, p):
        for i in range(n):
            ro = list(map(int, input().split()))
            ob.append(ro)
    res = -99999999999
    for open_at in product((0, 1), repeat=10):
        if 1 not in open_at:
            continue
        res = max(res, get_rieki(f, p, open_at, n))
    print(res)

def get_rieki(f, p, open_at, n):
    res = 0
    for i in range(n):
        cnt = 0
        for t in range(10):
            if f[i][t] == 1 and open_at[t] == 1:
                cnt += 1
        res += p[i][cnt]
    return res

main()

Submission status: Accepted

Solution code:
import itertools
N = int(input())
F, P = [], []
for _ in range(N):
    F.append(list(map(int, input().split())))
for _ in range(N):
    P.append(list(map(int, input().split())))
combinations = list(itertools.product((0, 1), repeat=10))[1:]
c = [0] * N
max_profit = -1000000001
for comb in combinations:
    profit = 0
    for i in range(N):
        c[i] = sum([F[i][jk] * comb[jk] for jk in range(10)])
        profit += P[i][c[i]]
    max_profit = max(max_profit, profit)
print(max_profit)

Submission status: Accepted

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

maxt = None
for i in range(1, 2**10):
  total = 0
  for _f, _p in zip(f, p):
    c = 0
    for bi, fi in zip(reversed(bin(i)[2:]), _f):
      if fi==1 and int(bi)==1:
        c += 1
    total += _p[c]
  maxt = max(total, maxt) if maxt is not None else total
print(maxt)

Submission status: Accepted

Solution code:
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]

ans = - 10 ** 10
for i in range(1, 2 ** 10):
    x = i
    A = []
    while x:
        A.append(x % 2)
        x //= 2
    while len(A) < 10:
        A.append(0)
        
    tmp = 0
    for j in range(n):
        cnt = 0
        for k in range(10):
            if F[j][k] == 1 and A[k] == 1:
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans, tmp)
    
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

open = []
earn = []

for _ in range(N):
    open.append(list(map(int, input().split())))

for _ in range(N):
    earn.append(list(map(int, input().split())))


ans = -float('inf')
for i in range(1, 1 << 10):
    tmp = 0
    same = [0]*N
    for j in range(N):
        for k in range(10):
            if open[j][k] == 1 and (i & (1 << k)):
                same[j] += 1

    for j in range(N):
        tmp += earn[j][same[j]]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
F = [[int(i) for i in input().split()] for i in range(n)]
P = [[int(i) for i in input().split()] for i in range(n)]

ans = -10 ** 10
for i in range(1, 2 ** 10):
    tmp = i
    A = []
    while tmp:
        A.append(tmp % 2)
        tmp //= 2
    while len(A) != 10:
        A.append(0)

    temp = 0
    for s in range(n):
        count = 0
        for t in range(10):
            if F[s][t] == 1 and A[t] == 1:
                count += 1
        temp += P[s][count]
    ans = max(ans, temp)
        
print(ans)

Submission status: Accepted

Solution code:
def calc_p(F, P, O):
    return P[sum(1 for f, o in zip(F, O) if f == 1 and o == 1)]

def calc_sum(Fs, Ps, O):
    return sum(calc_p(F, P, O) for F, P in zip(Fs, Ps))

def main(Fs, Ps):
    print(max(calc_sum(Fs, Ps, list(map(int, list('{0:010d}'.format(int(format(i, 'b'))))))) for i in range(1, 1024)))

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n = II()
F = [LI() for _ in range(n)]
P = [LI() for _ in range(n)]

ans = -INF
for bit in range(1, 1024):
    profit = 0
    for shop in range(n):
        cnt = 0
        for shift in range(10):
            if not bit >> shift & 1:
                continue

            if F[shop][shift]:
                cnt += 1

        profit += P[shop][cnt]

    ans = max(ans, profit)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
# len(info) == N,  len(info[i]) == 10
info = [list(map(int,input().split())) for i in range(N)]
p = [list(map(int,input().split())) for i in range(N)]

def bfs(list_hoge=[[]],depth=0):
    queue = []
    for e in list_hoge:
        for b in [0,1]:
            copy = e[:]
            copy.append(b)
            queue.append(copy)
    if depth == 10:
        return list_hoge[1:]
    list_hoge = queue[:]
    return bfs(list_hoge,depth+1)

ans = -float("inf")
for e in bfs():
    common = []
    for i in range(N):
        c = 0
        for j in range(10):   
            if e[j] == 1 and info[i][j] == 1:
                c += 1
        common.append(c)
    benefit = 0
    for i in range(N):
        c_i = common[i]
        benefit += p[i][c_i]
    if benefit > ans:
        ans = benefit
print(ans)

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)]

ans = -10**10
for i in range(1, 2**10):
    tmp = i
    b = []
    while tmp:
        b.append(tmp % 2)
        tmp //= 2
    while len(b) != 10:
        b.append(0)

    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if b[k] == 1 and F[j][k] == 1:
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans, tmp)

print(ans)

Submission status: Accepted

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

Ans = -9999999999
for i in range(1 << 10):
    xx = bin(i)[2::].zfill(10)
    if xx == "0000000000":
        continue
    
    ans = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if xx[j]=="1" and F[i][j]=="1":
                cnt += 1
        ans += P[i][cnt]

    Ans = max(Ans,ans)

print(Ans)

Submission status: Accepted

Solution code:
# coding: utf-8

II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N = II()
    F = [tuple(MI()) for _ in range(N)]
    P = [tuple(MI()) for _ in range(N)]
    TS = 10

    ans = -float("inf")
    s = set()
    for tt in range(1, 2**TS):
        ts_open = [min(1, tt & (1 << i)) for i in range(TS)]
        s.add(tuple(ts_open))
        a = 0
        for i in range(N):
            o = 0
            for j in range(TS):
                if ts_open[j] and F[i][j] == 1: o += 1
            a += P[i][o]
        ans = max(ans, a)
    return ans


if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
import itertools

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

answers = []
for bit in range(1, 2 ** 10):
    t = [min(1, bit & (1 << i)) for i in range(10)]
    answer = 0
    for i in range(n):
        c = sum(1 for j in range(10) if f[i][j] == 1 and t[j] == 1)
        answer += p[i][c]
    answers.append(answer)

print(max(answers))

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
F = [list(map(int,input().split())) for _ in range(n)]
P = [list(map(int,input().split())) for _ in range(n)]
max_profit = -10**9

for c in product(range(2),repeat=10):
    profit = 0

    if c == (0,0,0,0,0,0,0,0,0,0):
        continue

    for i in range(n): #cに対して、各店との共同営業日を確認していく
        common_business_day = 0
        for j in range(10):
            if c[j] == F[i][j] == 1:
                common_business_day += 1
        profit += P[i][common_business_day]
    
    max_profit = max(profit,max_profit)

print(max_profit)

Submission status: Accepted

Solution code:
N = int(input())
d1 = [int(input().replace(' ',''),2) for i in range(N)]
d2 = [list(map(int,input().split())) for l in range(N)]
ans = []


for i in range(1 << 10):
    if i != 0:
        sum = 0
        for j in range(N):
            temp = 0
            a = int(d1[j])
            b = a & i
            for k in range(10):
                if ((b >> k) & 1) == 1:
                    temp += 1
            else:
                sum += d2[j][temp]
        ans.append(sum)

print(max(ans))

Submission status: Accepted

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

a = list(range(10))
cnt = 0
total = 0
total_p = []
for i in range(1,11):
    c = list(itertools.combinations(a,i))
    
    for tap in c:
        for j in range(n):
            for num in tap:
                if f[j][num] == 1:
                    cnt += 1
                    
            total += p[j][cnt]
            cnt = 0
        
        total_p.append(total)
        total = 0

print(max(total_p))

Submission status: Accepted

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

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

res = -10**9
for b in range(1,2**10):
    bit = bin(b)[2:]
    bit = '0'*(10-len(bit))+bit
    tmp = 0
    for i in range(n):
        count = 0
        for j in range(10):
            if int(bit[j])==f[i][j]==1:
                count += 1
        tmp += p[i][count]
    res = max(res,tmp)
print(res)

Submission status: Accepted

Solution code:
# ABC 080 
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0 for i in range(n)]

N = int(input())
F = []
for i in range(N):
    F.append(getIntList())
#print(F)#
P = []
for i in range(N):
    P.append(getIntList())
#print(P)#

maxProf = -10**9
for n in range(1,2**10):
    a = zeros(10)
    m = n
    for i in range(10):
        a[i] = m % 2
        m //= 2
    prof = 0
    for i in range(N):
        c = 0
        for j in range(10):
            c += a[j]*F[i][j]
        prof += P[i][c]
    if prof>maxProf: maxProf = prof
print(maxProf)

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())))

is_open=[]
def count_score(is_open,N,F,P):
    is_open_copy=list(is_open)
    if len(is_open_copy)==10:
        flag = True
        for t in is_open_copy:
            if t:
                flag=False
                break
        if flag:
            return -10**27
        count_N = [0 for i in range(N)]
        for i in range(N):
            for j in range(10):
                if is_open[j] and F[i][j]==1:
                    count_N[i]+=1
        score = 0
        for i in range(N):
            score+=P[i][count_N[i]]
        return score
    return max(count_score(is_open_copy+[True],N,F,P),count_score(is_open_copy+[False],N,F,P))

print(count_score(is_open,N,F,P))

Submission status: Accepted

Solution code:
ls = []
def onoff(n):
    global ls
    if len(n) == 10:
        ls.append(n)
    else:
        onoff(n + '0')
        onoff(n + '1')
onoff('0')
onoff('1')
del ls[0]
n = int(input())
f = [list(map(str,input().split())) for x in range(n)]
p = [list(map(int,input().split())) for x in range(n)]
ans = -99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
for i in range(1023):
    check = 0
    for j in range(n):
        count = 0
        for k in range(10):
            if ls[i][k] == f[j][k] and ls[i][k] == '1':
                count += 1
        check += p[j][count]
    ans = max(ans,check)
print(ans)

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 = []

for i in range(2**10):
    tmp = 0
    for j in range(N):
        num = 0
        for index, k in enumerate(F[j]):
            if k == 1:

                if i & 2**index:
                    num += 1
        tmp += P[j][num]
    ans.append(tmp)
ans = ans[1:]
print(max(ans))