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 = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]

cross = [0]*n
profit = 0
max = 0
for i in range(n):
    if f[i][0] == 1:
        cross[i] = cross[i] + 1

for i in range(n):
    for j in range(10):
        if cross[i] == j:
            profit = profit + p[i][j]

max = profit
cross = [0]*n
profit = 0

for day in range(1, 2047):
    S = format(day, 'b').zfill(10)
    ### それぞれのopeningdayについて、crossというn項のリストをつくる。pというprofitを計算し、maxと比較する。
    for j in range(10):
        if S[j] == str(1):
            for i in range(n):
                if f[i][j] == 1:
                   cross[i] = cross[i] + 1

    for i in range(n):
        for j in range(10):
           if cross[i] == j:
               profit = profit + p[i][j]

    if profit >= max:
        max = profit
    
    cross = [0]*n
    profit = 0

print(max)

Submission status: Accepted

Solution code:
N = int(input())
# F[y][x]: y行目、x文字目
F = [list(map(int, input().split())) for _ in range(N)]
# P[y][x]: y行目、x文字目
P = [list(map(int, input().split())) for _ in range(N)]

max_num = -10000001 * 1000
sum = 0

for i in range(1024):
    if i == 0:
        continue
    b = bin(i)
    for n in range(N):
        f = F[n]
        s = ""
        for _n in range(10):
            s += str(f[_n])
        s = "0b" + s
        and_num = int(b, 0) & int(s, 0)
        match_nums = list(format(and_num, 'b'))
        match_num = 0
        for _n in match_nums:
            if int(_n) == 1:
                match_num += 1
        sum += P[n][match_num]
    if sum > max_num:
        max_num = sum
    sum = 0
print(max_num)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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())))

e_list = []

for i in range(1,1024):
    temp = i
    temp_l = []
    for j in range(10):
        temp_l.append(temp % 2)
        temp = temp // 2

    temp_l.reverse()
    e_list.append(temp_l)

ans = []

for wk in e_list:
    plice = 0
    for fi,pi in zip(F,P):
        c_num = 0
        for f,e in zip(fi,wk):
            if e == 1 and e == f:
                c_num += 1

        plice += pi[c_num]
    ans.append(plice)

print(max(ans))

Submission status: Accepted

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

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

num = -float("inf")
for i in range(1, 1 << 10):
    tmp = 0
    for k in range(N):
        rec = 0
        for j in range(10):
            if i & 1 << j and F[k][j]:
                rec += 1
        tmp += P[k][rec]
    num = max(num, tmp)

print(num)

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 k in range(1,1<<10):
    tmp = 0
    for fs,ps in zip(F,P):
        cnt = 0
        for b in range(10):
            if (k>>b)&1 and fs[b]:
                cnt += 1
        tmp += ps[cnt]
    ans = max(ans, tmp)
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)]

res = []
for i in range(1, 2**10 + 1):
    index = list("0000000000")
    binary = list(bin(i)[2:])
    index[-len(binary):] = binary
    index = list(map(int, index))
    kaburi = [sum([i * f for i, f in zip(index, F[n])]) for n in range(N)]
    res.append(sum([P[n][k] for n, k in zip(range(N), kaburi)]))

print(max(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 = -float('inf')
for k in range(1,1<<10):
    tmp = 0
    for fs,ps in zip(F,P):
        cnt = 0
        for b in range(10):
            if (k>>b)&1 and fs[b]:
                cnt += 1
        tmp += ps[cnt]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def dfs(depth:int, inbis:str, f:list, p:list):
    if depth != 10:
        return max(dfs(depth+1, inbis+"1",f,p),
                   dfs(depth+1, inbis+"0",f,p))
        
    else:
        if inbis.count("1") == 0:
            return -10**10
        else:
            biz = [int(i) for i in inbis]
            ans = 0
            for i in range(len(f)):
                common = [biz[j]*f[i][j] for j in range(10)]
                ans += p[i][sum(common)]
                
            return ans

n = ni()
f = []
p = []
for _ in range(n):
    f.append(list(li()))
for _ in range(n):
    p.append(list(li()))
    
print(dfs(0,"",f,p))

Submission status: Accepted

Solution code:
#ABC080C
import numpy as np
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=-1*pow(10,10)
ans_tmp=0
Self=[0]*10
c=0
#営業時間を仮定
for i in range(pow(2,10)):
    ans_tmp=0
    if i !=0:
        i_tmp = i
        for j in range(10):
            Self[j]=i_tmp//pow(2,9-j)
            i_tmp-=Self[j]*pow(2,9-j)
        for k in range(N):
            c=np.dot(F[k],Self)
            ans_tmp+=P[k][c]
        if ans<ans_tmp:
            ans=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)]
P_list = []


for i in range(1, 2 ** 10):
    a = list(bin(i))[2::]
    while len(a) < 10:
        a = ["0"] + a
    P_list.append(a)
finalans = -1000000000000000
for i in P_list:
    ans = 0
    cnt = [0 for i in range(N)]
    for j in range(10):
        if i[j] == "1":
            for k in range(N):
                if F[k][j] == 1:
                    cnt[k] += 1
    for j in range(N):
        ans += P[j][cnt[j]]
    #print(ans)
    finalans = max(finalans, ans)

print(finalans)

Submission status: Accepted

Solution code:
from itertools import product
al=list(product([0,1],repeat=10))
n=int(input())
a=[list(map(int, input().split())) for i in range(n)]
p=[list(map(int, input().split())) for i in range(n)]
ans=-100000000000
for i in al:
    if sum(i)==0:continue
    q=0
    for j in range(n):
        count=0
        for k in range(10):
            if a[j][k]==1 and i[k]==1:
                count+=1
        q+=p[j][count]
    ans=max(ans,q)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
opengrid = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    opengrid.append(array)
benefit = []
for i in range(N):
    array = list(map(int, input().strip().split(' ')))
    benefit.append(array)
i = 1
st = []
while i <= 1023:
  x = bin(i)[2:]
  y = '0'*(10-len(x))+x
  z = []
  for chara in y:
    z.append(int(chara))
  st.append(z)
  i += 1
maxx = -99999999999
for pat in st:
  j = 0
  ans = 0
  while j < N:
    v1 = np.array(pat)
    v2 = np.array(opengrid[j])
    x = np.dot(v1,v2)
    ans += benefit[j][x]
    j += 1
  maxx = max(maxx,ans)
print(maxx)

Submission status: Accepted

Solution code:
from itertools import product
N = int(input())
F = []
for i in range(N):
    F.append([int(i) for i in input().split()])
P = []
for i in range(N):
    P.append([int(i) for i in input().split()])

ans = -float('inf')

def culc(F, P, l):
    ret = 0
    for i in range(N):
        c = sum([j == k == 1 for j, k in zip(F[i], l)])
        ret += P[i][c]
    return ret

for l in product([0,1],repeat=10):
    if sum(l) == 0:
        continue
    ans = max(ans, culc(F, P, l))
print(ans)

Submission status: Accepted

Solution code:
f = lambda: list(map(int,input().split()))

n = int(input())
F = [f() for _ in range(n)]
P = [f() for _ in range(n)]

from itertools import product
mul = product((0, 1), repeat=10)

ans = -float('inf')
for m in mul:
    if any(m):
        ben = 0
        for shop in range(n):
            op = sum(m[j] & F[shop][j] for j in range(10))
            ben += P[shop][op]
        ans = max(ans,ben)
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 bit in range(1, 1<<10):
    score = 0
    for i in range(n):
        time = 0
        for t in range(10):
            if bit&(1<<t) and f[i][t] == 1:
                time += 1
        score += p[i][time]
    ans = max(ans, score)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-

def zehnpaard():
    from itertools import product

    n = int(input())
    fs = [[int(x) for x in input().split()] for _ in range(n)]
    ps = [[int(x) for x in input().split()] for _ in range(n)]

    xs = product((0, 1), repeat=10)
    next(xs)
    print(max(sum(p[sum(a==b==1 for a, b in zip(f, x))] for f, p in zip(fs, ps)) for x in xs))

def solver():
    import itertools
    N = int(input())

    # implements
    Fs = [list(map(int, input().split())) for n in range(N)]
    Ps = [list(map(int, input().split())) for n in range(N)]

    # joisino姉がお店を開く全組み合わせ
    Xs = itertools.product([0,1], repeat=10)
    next(Xs) # すべて0を除く

    ans = (-10**7)*N
    for x in Xs:
        profit = 0
        for n in range(N):
            c = 0
            for a, b in zip(x, Fs[n]):
                if a==b==1:
                    c += 1
            profit += Ps[n][c]
        ans = max(ans, profit)
    print(ans)


if __name__ == "__main__":
    solver()

Submission status: Accepted

Solution code:
n = int(input())
f = [int(input().replace(' ', ''), 2) for i in range(n)]
p = []
for i in range(n):
    p.append([int(v) for v in input().split()])

ans = -10000000000
for store in range(1, 1024):
    p_sum = 0
    for i, v in enumerate(f):
        c = v & store
        p_sum += p[i][bin(c).count('1')]
    ans = max(ans, p_sum)

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())

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

ans = -INF
for i in range(1, 1 << 10):

    score = 0
    for shop in range(N):

        both_open = 0
        for period in range(10):
            if i >> period & F[shop][period] == 1:
                both_open += 1

        score += P[shop][both_open]

    ans = max(ans, score)

print(ans)

Submission status: Accepted

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

ret = -float('inf')
for i in range(1, 1024):
    k = 0
    for a in range(N):
        count = 0
        for j in range(10):
            if F[a][j] == 1 and i & (1 << j) > 0:
                count += 1
        k += D[a][count]

    ret = max(ret, k)

print(ret)

Submission status: Accepted

Solution code:
from itertools import product

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


# 全探索
best_score = float("-inf")

for i in product((0, 1), repeat=10):
    if sum(i) == 0:
        continue

    score = 0
    for k in range(n):
        num = sum([p * q for p, q in zip(i, F[k])])
        score += P[k][num]

    best_score = max(best_score, score)

print(best_score)

Submission status: Accepted

Solution code:
import math
N = int(input())
F = [[] * 10 for i in range(N)]
for i in range(N):
    F[i] = list(map(int, input().split()))
P = [[] * 11 for i in range(N)]
for i in range(N):
    P[i] = list(map(int, input().split()))
L = [0] * 10
Sum_max = -float("inf")
for i in range(1, 1024):
    for j in range(10):
        L[j] = i % 2
        i = int(i / 2)
    Sum = 0
    for j in range(N):
        count = 0
        for k in range(10):
            if L[k] == 1 and F[j][k] == 1:
                count += 1
        Sum += P[j][count]
    Sum_max = max(Sum_max, Sum)
print(Sum_max)

Submission status: Accepted

Solution code:
N=int(input())
F=[]
for i in range(N):
    tmp=list(input().split())
    F.append(int(''.join(tmp)))
P=[list(map(int, input().split())) for _ in range(N)]
ans=-float("inf")
for i in range(1,1<<10):
    s=[]
    for j in range(N):
        tmp=str(bin(i & int(str(F[j]), 2)))
        s.append(P[j][sum(list(map(int, list(tmp[2:]))))])
    if ans<sum(s):
        ans=sum(s)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    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())))

    ans = -INF
    for p in product([0, 1, 2, 3], repeat=5):
        if sum(p) == 0:
            continue
        t = 0
        for n in range(N):
            num = 0
            for y in range(0, 10, 2):
                if p[y // 2] == 1:
                    num += F[n][y]
                if p[y // 2] == 2:
                    num += F[n][y + 1]
                if p[y // 2] == 3:
                    num += F[n][y] + F[n][y + 1]

            t += P[n][num]
        ans = max(ans, t)
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import product

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 = -1e9-1
for i in product((0,1),repeat=10):
  gain = 0
  if i == (0,0,0,0,0,0,0,0,0,0):
    continue
  for j in range(N):
    cnt = 0
    for k in range(10):
      cnt += i[k]*F[j][k]
    gain += P[j][cnt]
  ans = max(ans,gain)

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

N = int(input())
F = [int(input().replace(' ', ''), 2) for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

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

Submission status: Accepted

Solution code:
N = int(input())
F = [0 for i in range(N)]
P = [0 for i in range(N)]
for i in range(N):
  F[i] = [int(x) for x in input().split()]
for i in range(N):
  P[i] = [int(x) for x in input().split()]
ans = -10 * 10 ** 9
for c in range(1, 2 ** 10):
  pat = ('0' * 9 + bin(c)[2:])[-10:]
  ans = max(sum([P[i][sum([F[i][j] * int(pat[j]) for j in range(10)])] for i in range(N)]), ans)
print(ans)

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    F = [0 for i in range(n)]
    P = [0 for i 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()))

    ans = 0
    Flag = "first"

    for z in range(1,1024):
        ans_list = list(map(int,list(format(z,"010b"))))
        pro = 0

        for i in range(n):
            tmp = 0
            for j in range(10):
                if ans_list[j] == 1 and F[i][j]== 1:
                    tmp += 1

            pro += P[i][tmp]

        if Flag == "first":
            ans = pro
            Flag = False

        ans = max(ans, pro)


    print(ans)


if __name__ == "__main__":
        main()

Submission status: Accepted

Solution code:
import sys
from itertools import product

input = sys.stdin.readline

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

ans = float('-inf')
for ptn in product([0, 1], repeat=10):
    if sum(ptn) == 0:
        continue

    res = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            cnt += F[i][j] * ptn[j]
        res += P[i][cnt]
    ans = max(ans, res)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
f_list = []
p_list = []

for i in range(N):
    f = input()
    f_list.append(f)
for i in range(N):
    p = list(map(int, input().split()))
    p_list.append(p)

profit = []
for i in range(1, 2**10):
    sum = 0
    for f, p in zip(f_list, p_list):
        f = int(f.replace(" ", ""), 2)
        c = bin(f & i).count("1")
        sum += p[c]
    profit.append(sum)
print(max(profit))

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 calcBit(num):
    res = []
    for _ in range(10):
        res.append(num%2)
        num >>= 1
    return res

ans = -float('inf')
for i in range(1,2**10):
    ans_t = 0
    for k,l in enumerate(f):
        tmp = 0
        for (a,b) in zip(l,calcBit(i)):
            if a==1 and b==1:
                tmp += 1
        ans_t += p[k][tmp]
    ans = max(ans,ans_t)

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
FF = [inpl() for i in range(N)]
PP = [inpl() for i in range(N)]

ans = -INF
for flags in itertools.product([0,1], repeat=10):
	if sum(flags) == 0: continue
	tans = 0
	for i in range(N):
		tmp = 0
		for c in range(10):
			if FF[i][c] and flags[c]:
				tmp += 1
		tans += PP[i][tmp]
	ans = max(tans,ans)

print(ans)

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

for i in product([0,1],repeat=10):
  if i==(0,0,0,0,0,0,0,0,0,0):continue
  s=0
  for (idx,j) in enumerate(f):
    s+=p[idx][sum(k*l for (k,l) in zip(i,j))]
  cd.extend([s])
print(max(cd))

Submission status: Accepted

Solution code:
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())))

res = -1e20
for i in range(2**10):
	bs = format(i, "#012b")[2:]
	
	if bs == "0000000000": continue
	cnt = 0
	
	for j in range(N):
		tmp = 0
		for k in range(10):
			if F[j][k] == 1 and bs[k] == '1':
				tmp+=1
		cnt += P[j][tmp]
	
	res = max(cnt, res)
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from itertools import combinations

n = int(input())

f = []

for _ in range(n):
    line = list(map(lambda n:int(n),input().split(" ")))
    f.append(line)

p = []
for _ in range(n):
    line = list(map(lambda n:int(n),input().split(" ")))
    p.append(line)

def overlap(ary1,ary2):
    ret = 0
    for i in range(len(ary1)):
        if ary1[i]==ary2[i] and ary1[i]==1:
            ret += 1
    return ret

def calcProf(jary):
    # 各時間帯で店を開くかどうかの情報を元に、利益を計算する
    ret = 0
    for i in range(n):
        lap = overlap(jary, f[i])
        ret += p[i][lap]
    return ret

def conv(ary):
    ret = [0 for _ in range(10)]
    for i in ary:
        ret[i] = 1
    return ret

prof = -1000000000
for e in range(1,11):
    for elem in combinations(range(10), e):
        cp = calcProf(conv(elem))
        if cp>prof:
            prof = cp

print(prof)

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)]
cost=-float("inf")
for i in range(1,1<<10):
    ans=0
    for j in range(n):
        cnt=0#自分が作ったbitと配列fで被っているところの数を数える
        for k in range(10):
            if i&(1<<k) and f[j][k]==1:
                cnt+=1
        ans+=p[j][cnt]
    cost=max(ans,cost)
print(cost)

Submission status: Accepted

Solution code:
N=int(input())
 
F=[]
P=[]
 
for i in range(N):
    tmp=list(map(int, input().split()))
    F.append(tmp)
 
for i in range(N):
    tmp=list(map(int, input().split()))
    P.append(tmp)
 
max_sum=-1000000001
 
for i in range(1,1024):
    bin=[0]*10 #0,1で午前午後を表している
    now=i
    for j in range(10):
        bin[j]=now%2
        now=now//2
        #今回のパターンbinを作成完了
    ans_sum=0
    for j in range(N):
        ans=0
        for h in range(10):
            if F[j][h]*bin[h]==1:
                ans+=1
        ans_sum+=P[j][ans]
    if max_sum<ans_sum:
        max_sum=ans_sum
 
print(max_sum)

Submission status: Accepted

Solution code:
N = int(input())
isopen = []
profit = []

for i in range(N) :
    isopen.append(list(input().split()))
    
for i in range(N) :
    profit.append(list(map(int, input().split())))
    
# permutation of available open periods 
perms = []
def perm(s, idx) :
    if idx == 10 :
        if s != "0000000000" :
            perms.append(s)
    else :
        perm(s + "0", idx + 1)
        perm(s + "1", idx + 1)
        
perm("", 0)

def doand(s1, s2) :
    cnt = 0
    for i in range(10) :
        if s1[i] == s2[i] == "1" :
            cnt += 1
            
    return cnt 

max_cost = -10**20

for p in perms :
    cost_over = 0
    # for each branch
    for i in range(N) : 
        # bit AND for current permutation and branch -> fetch count
        numsame = doand(p, "".join(isopen[i]))
        
        # fetch profit based on count for branch 
        cost_over += profit[i][numsame]
    
    max_cost = max(max_cost, cost_over)
    
print(max_cost)

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)]
ans = - 10**10
for X in product( range(2), repeat = 10):
    if X == tuple([0]*10):
        pass
    else:
        c = 0
        for i in range(N):
            n = 0
            for j in range(10):
                if F[i][j] == 1 and X[j] == 1:
                    n += 1
            c += P[i][n]
        ans = max(ans, c)
print(ans)

Submission status: Accepted

Solution code:
import sys
r=sys.stdin.readline
N=int(r())
F=[int(r().replace(' ',''),2)for _ in[0]*N]
P=[list(map(int,r().split()))for _ in[0]*N]
print(max(sum([p[bin(f&i).count('1')]for f,p in zip(F,P)])for i in range(1,2**10)))

Submission status: Accepted

Solution code:
N=int(input())
F=[int(input().replace(' ',''),2)for _ in[0]*N]
P=[list(map(int,input().split()))for _ in[0]*N]
print(max(sum([p[bin(f&i).count('1')]for f,p in zip(F,P)])for i in range(1,2**10)))

Submission status: Accepted

Solution code:
N=int(input())
F=[int(input().replace(' ',''),2)for _ in[0]*N]
P=[list(map(int,input().split()))for _ in[0]*N]
ans = -float('inf')
for i in range(1,2**10):
    sum = 0
    for k in range(N):
        sum += P[k][bin(F[k]&i).count('1')]
    if ans < sum:
        ans = sum
print(ans)

Submission status: Accepted

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

ans = -(10 ** 9)
# bin(100) '0b1100100'
# ビットで組み合わせを考えてる
for item in range(1, 1024):
    fund = 0
    for i in range(n):
        cou = 0
        for x in range(10):
            if (item >> x) % 2 == 1 and arr[i][x] == 1:
                cou += 1
        fund += arm[i][cou]
    ans = max(ans, fund)
print(ans)

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-

def main():
    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)]

    max_profit = -1000000001
    
    for i in range(1, 2 ** 10):
        binary=[0]*10
        now=i
        for j in range(10):
            binary[j]=now%2
            now=now//2
        profit = 0
        for j in range(n):
            one_cnt = 0
            for h in range(10):
                if f_list[j][h]*binary[h]==1:
                    one_cnt += 1
            profit += p_list[j][one_cnt]
        if max_profit < profit:
            max_profit = profit
 
    print(max_profit)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#N,A,B=map(int, input().split())
 
#A=list(map(int, input().split()))
 
N=int(input())
 
F=[]
P=[]
 
for i in range(N):
    tmp=list(map(int, input().split()))
    F.append(tmp)
 
for i in range(N):
    tmp=list(map(int, input().split()))
    P.append(tmp)
 
max_sum=-1000000001
 
for i in range(1,1024):
    bin=[0]*10
    now=i
    for j in range(10):
        bin[j]=now%2
        now=now//2
    ans_sum=0
    for j in range(N):
        ans=0
        for h in range(10):
            if F[j][h]*bin[h]==1:
                ans+=1
        ans_sum+=P[j][ans]
    if max_sum<ans_sum:
        max_sum=ans_sum
 
print(max_sum)

Submission status: Accepted

Solution code:
n = int(input())
F = [list(map(int, input().split())) for _ in range(n)]#F[i]は(i+1)番目の店の営業の有無のリスト
P = [list(map(int, input().split())) for _ in range(n)]#P[i]は(i+1)番目の店との同時開店数に応じた利益のリスト

ans = (-1) * 10 ** 9
for i in range(2 ** 10):
    if sum(map(int, list(str(i)))) == 0:
        continue
    cnt_lst = [0 for _ in range(n)]
    for d in range(5):
        for t in range(2):
            dt = 2 * d + t
            if i & (2 ** dt) != 0:
                for j in range(n):
                    cnt_lst[j] += F[j][dt]
    buf = 0
    for j in range(n):
        buf += P[j][cnt_lst[j]]
    ans = max(buf, ans)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

f = np.array(F)
ans = float("-inf")
for n in range(1, 2**10):
    a = np.array([int(x) for x in format(n, '010b')])
    p = sum([P[i][x] for i,x in enumerate(np.sum(f * a, axis=1))])
    ans = max(ans, p)
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
O = defaultdict(list)
for i in range(n):
    F = list(map(int, input().split()))
    for j in range(10):
        if F[j] == 1:
            O[j].append(i)
P = []
for _ in range(n):
    _P = list(map(int, input().split()))
    P.append(_P)

max_x = -1 * 10 ** 10
for i in range(1, 1024):
    v = i
    K = [] # Kaburi
    for j in range(10):
        if v % 2 == 1:
            K.extend(O[j])
        v //= 2
    #print(K)
    x = 0
    for l in range(n):
        k = K.count(l)
        x += P[l][k]
    max_x = max(max_x, x)
print(max_x)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
F = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]

f = np.array(F)
ans = float('-inf')
for n in range(1, 2**10):
    a = np.array([int(x) for x in bin(n)[2:].rjust(10, '0')])
    p = sum([P[i][x] for i,x in enumerate(np.sum(f * a, axis=1))])
    ans = max(ans, p)
print(ans)

Submission status: Accepted

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

def profit(action):
    p = 0
    for i in range(N):
        ci = sum([int(action[j]) * F[i][j] for j in range(10)])
        p += P[i][ci]
    return p

pmax = -float('inf')
for i in range(1, 1024):
    pmax = max(pmax, profit(format(i, '010b')))
print(pmax)

Submission status: Accepted

Solution code:
N = int(input())
F = [[int(x) for x in input().split()] for i in range(N)]
P = [[int(x) for x in input().split()] for i in range(N)]
ans = -10 ** 9
for i in range(1, 2 ** 10):
  pat = bin(i)[2:]
  pat = ['0' for i in range(10 - len(pat))] + list(pat)
  benefit = 0
  for j in range(N):
    benefit += P[j][sum([int(pat[k]) * F[j][k] for k in range(10)])]
  ans = max(ans, benefit)
print(ans)

Submission status: Accepted

Solution code:
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())))

TIME = 10
prof_cand = []

for bit in range(1,1<<TIME):
    onBiz = []
    with_n = []
    for t in range(TIME):
        if bit & (1<<t):
            onBiz.append(1)
        else:
            onBiz.append(0)
            
    for n in range(N):
        with_n.append(sum([F[n][i]*onBiz[i] for i in range(TIME)]))
    
    prof = sum([P[i][with_n[i]] for i in range(N)])
    prof_cand.append(prof)
    
print(max(prof_cand))