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:
INF = 100000000000

from itertools import product
N = int(input())
is_opens = []
all_open = [0 for i in range(10)]

for n in range(N):
  l = list(map(int, input().split()))
  for i in range(len(l)):
    all_open[i] = 1 if l[i] == 1 else all_open[i] 
  is_opens.append(l)
must_true = set([i for i in range(len(all_open)) if all_open[i] == 0])

values = []
for n in range(N):
  values.append(list(map(int, input().split())))

patterns = product([0,1], repeat=10)
ans = -INF
for pattern in patterns:
  trues = set([i for i in range(len(pattern)) if pattern[i] == 1])
  if not must_true.issubset(trues) or trues == set():
    continue 

  tmp = 0
  for n in range(N):
    count = sum([1 for i in range(10) if pattern[i] == 1 and pattern[i] == is_opens[n][i]])
    value = values[n][count]
    tmp += value
  ans = max(ans, tmp)

print(ans)

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    n=int(input())

    f=[]
    for i in range(n):
        fi=list(map(int,input().split()))
        f.append(fi)
    p=[]
    for i in range(n):
        pi=list(map(int,input().split()))
        p.append(pi)
elif icase==1: 
    n=1
    f=[[1, 1, 0, 1, 0, 0, 0, 1, 0, 1]]
    p=[[3, 4, 5, 6, 7, 8, 9, -2, -3, 4, -2]]
elif icase==2: 
    n=2
    f=[[1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]]
    p=[[0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1],
       [0, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1]]
elif icase==3: 
    n=3
    f=[[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]]
    p=[[-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]]
    
import itertools
sumpmax=-10**11
for i in itertools.product([0,1], repeat=10):
    r=list(i)
    sump=0
    if sum(r)!=0:
        for jj in range(n):
            ci=0
            for j in range(10):
                ci=ci+r[j]*f[jj][j]
            sump=sump+p[jj][ci]
#            print(sump,r)
        sumpmax=max(sump,sumpmax)
print(sumpmax)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
f=lambda:[list(map(int,input().split())) for _ in range(n)]
n=int(input())
llf,llp=f(),f()
a=-10**9
import itertools as it
for t in it.product([0,1],repeat=10):
  if sum(t):
    lc=[sum(t[i]*lf[i] for i in range(10)) for lf in llf]
    a=max(a,sum(llp[i][lc[i]] for i in range(n)))
print(a)

Submission status: Accepted

Solution code:
N = int(input())

F=[int(input().replace(" ",""),2) for i in range(N)]
#f = [list(map(int, input().split())) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = - 10**18
for i in range(1, 2**10):
    s = 0
    for f,p in zip(F,P):
        s += p[bin(f&i).count("1")]
    ans = max(ans, s)
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=-10**18
for i in range(1,2**10):
  op=[0]*10
  res=0
  for j in range(10):
    if i>>j&1:
      op[j]=1
  for j in range(n):
    cnt=0
    for k in range(10):
      if op[k]&f[j][k]:
        cnt+=1
    res+=p[j][cnt]
  ans=max(ans,res)
print(ans)

Submission status: Accepted

Solution code:
def solve():
    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 ** 9
    for s in range(1, 1 << 10):
        benefit = 0
        for i in range(N):
            cnt = 0
            for j in range(10):
                if s >> j & 1 and F[i][j] == 1:
                    cnt += 1
            benefit += P[i][cnt]
        ans = max(ans, benefit)
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from itertools import product
import numpy as np
from sys import maxsize

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

res = -maxsize
for arr in product(range(2), repeat=10):
    if sum(arr) == 0:
        continue
    a = np.array(arr)
    profit = 0
    for i in range(n):
        profit += p[i][np.sum(a*f[i])]
    if profit > res:
        res = profit

print(res)

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 ** 9

for bit in range(1, 2 ** 10):
    cc = 0
    for i in range(n):
        c = 0
        for j in range(10):
            if bit & (1<<j) and f[i][j]:
                c += 1
        cc += p[i][c]
    ans = max(ans, cc) 
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
arr=[list(map(int,input().split())) for i in range(n)]
arm=[list(map(int,input().split()))for j in range(n)]
ans=-9999999999
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:
import sys
sys.setrecursionlimit(114514)

def g(i):
    global m
    if i == 10:
        if not sum(s) == 0:
            x = 0
            for j in range(n):
                c = 0
                for k in range(10):
                    if s[k] == f[j][k] == 1:
                        c += 1
                x += p[j][c]
            if m < x:
                m = x
        return
    g(i + 1)
    s[i] = 1
    g(i + 1)
    s[i] = 0

n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
s = [0] * 10
m = -10 ** 9
g(0)
print(m)

Submission status: Accepted

Solution code:
import sys
n = int(input())

array = []
for i in range(n):
  f = input().replace(' ', '')
  f = int(f, 2)
  array.append(f)
  
p = []
for i in range(n):
  tmp = list(map(int, input().split()))
  p.append(tmp)
  
ans = -sys.maxsize
for i in range(1,2 ** 10):
  profit = 0
  for j in range(len(array)):
    s = bin(array[j] & i).replace('0b', '').replace('0', '')
    profit += p[j][len(s)]
    
  ans = max(ans, profit)
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 i in range(1,1024):
    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if (i>>k & 1) & F[j][k]:
                cnt += 1
        tmp += P[j][cnt]
    ans = max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
class Solution:
    def solve(self, N: int, F, P) -> int:

        answer = - 10**10

        def list2int(li) -> int:

            base = 1
            ret = 0
            for b in li:
                ret += base * b
                base *= 2
            return ret

        def int2list(i: int):
            ret = []
            for _ in range(10):
                ret.append(i % 2)
                i //= 2

            return ret

        F_int = [list2int(f) for f in F]

        for j in range(1, 1024):
            s = 0
            for n, f in enumerate(F_int):
                cn = sum(int2list(j & f))
                s += P[n][cn]

            answer = max(answer, s)

        return answer


if __name__ == '__main__':

    # standard input
    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())))

    # solve
    solution = Solution()
    print(solution.solve(N, F, P))

Submission status: Accepted

Solution code:
n = int(input())
f = []
p = []
for _ in range(n):
    tmp = [int(x) for x in input().split()]
    f.append(tmp)
for _ in range(n):
    tmp = [int(x) for x in input().split()]
    p.append(tmp)

ans = -10 ** 10

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

Submission status: Accepted

Solution code:
N=int(input())
Flist=[]
for a in range(N):
    list=[]
    F=input().split()
    for b in F:
        list.append(int(b))
    Flist.append(list)
Plist=[]
for a in range(N):
    list=[]
    F=input().split()
    for b in F:
        list.append(int(b))
    Plist.append(list)
FFlist=[]
for a in range(N):
    list=[]
    item = Flist[a]
    n = len(item)
    for i in range(2 ** n):
        bag = []
        for j in range(n):
            if ((i >> j) & 1):
                bag.append(item[j])
        z=sum(bag)
        list.append(z)
    del list[0]
    FFlist.append(list)
goukei=[]
for a in range(2**10-1):
    c=0
    for b in range(N):
        c+=Plist[b][FFlist[b][a]]
    goukei.append(c)
print(max(goukei))

Submission status: Accepted

Solution code:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    F = XLMIIS(N)
    P = XLMIIS(N)
    T = 10
    ans = - 10**7*N
    for bit in range(1,2**T):
        c = [0] * N
        for i in range(T):
            if bit & (1<<i):
                for j in range(N):
                    c[j] += F[j][i]
        benefit = 0
        for i in range(N):
            benefit += P[i][c[i]]
        ans = max(ans,benefit)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    F = XLMIIS(N)
    P = XLMIIS(N)
    def b(i,c,num_both):
        if i == 10:
            if num_both == 0:
                return -(10**7)*N
            benefit = 0
            for j, p in enumerate(P):
                benefit += p[c[j]]
            return benefit
        c_both = c[:]
        num_both_2 = num_both
        for j in range(N):
            c_both[j] += F[j][i]
            num_both_2 += F[j][i]

        return max(b(i+1,c,num_both),b(i+1,c_both,num_both_2))
    print(b(0,[0]*N,0))


if __name__ == '__main__':
    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)]

ans = -float('inf')
for x in list(itertools.product([0, 1], repeat=10)):
    if x.count(0) == 10:
        continue
    total = 0
    for i in range(N):
        count = 0
        for j in range(10):
            count += x[j] & F[i][j]
        total += P[i][count]
    ans = max(ans, total)
print(ans)

Submission status: Accepted

Solution code:
# bit全探索

n = int(input())
eigyou = [list(map(int, input().split())) for _ in range(n)]
profits = [list(map(int, input().split())) for _ in range(n)]
# 全休業を除く = 0を除外して、1〜1023まで回す
# 10 = 0000001010 ならば、木曜午前と金曜午前に営業することを示す

ans = -(10 ** 7) * 100 - 10
for i in range(1, 2**10):
    eigyou_here = [-1] * 10
    temp = 0
    for digit in range(10):
        eigyou_here[10 - 1 - digit] = int(i & (2 ** digit) > 0)
    for j_shop in range(n):
        import numpy as np
        coincide_time = np.dot(eigyou[j_shop], eigyou_here)
        # for time in range(10):
        #     coincide_time += eigyou[j_shop][time] * eigyou_here[time]
        temp += profits[j_shop][coincide_time]

    ans = max(ans, temp)

print(ans)

Submission status: Accepted

Solution code:
# bit全探索

n = int(input())
eigyou = [list(map(int, input().split())) for _ in range(n)]
profits = [list(map(int, input().split())) for _ in range(n)]
# 全休業を除く = 0を除外して、1〜1023まで回す
# 10 = 0000001010 ならば、木曜午前と金曜午前に営業することを示す

ans = -(10 ** 7) * 100 - 10
for i in range(1, 2**10):
    eigyou_here = [-1] * 10
    temp = 0
    for digit in range(10):
        eigyou_here[10 - 1 - digit] = int(i & (2 ** digit) > 0)
    for j_shop in range(n):
        coincide_time = 0
        for time in range(10):
            coincide_time += eigyou[j_shop][time] * eigyou_here[time]
        temp += profits[j_shop][coincide_time]

    ans = max(ans, temp)

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
N=int(input())
F=[]
P=[]
for i in range(N):
    row=list(map(int,input().split()))
    F.append(row)

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

ans=-10**10

for i in range(1,2**10):
    IB=list(format(i,'010b'))
    uriage=0
    for j in range(N):
        cnt=0
        for k in range(10):
            if F[j][k]==int(IB[k])==1:
                cnt+=1
        uriage+=P[j][cnt]
    ans=max(ans,uriage)

print(ans)

Submission status: Accepted

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

ans = - 10**10

def cost(i) :
    tem = 0
    for j in range(N) :
        d = bin(i & F2[j]).count("1")
        tem += P[j][d]
    return tem

for i in range(1, 2**10) :
    ans = max(ans, cost(i))

print(ans)

Submission status: Accepted

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

N = int(input().strip())
F_list = [list(map(int, input().rstrip().split())) for i in range(N)]
P_list = [list(map(int, input().rstrip().split())) for i in range(N)]
#-----

total_profit_list=[]
for x in range(1,2**10):
    bin_str = format(x, 'b').zfill(10)

    profit=0
    for i in range(N):
        c=0
        for j in range(10):
            if int(bin_str[j]) == F_list[i][j] == 1:
                c += 1
        profit += P_list[i][c]
    
    total_profit_list.append(profit)

print(max(total_profit_list))

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

# for i in range(N):
#     print(bin(F[i]))

ans = -10**9
for bit in range(1, 1<<10):
    money = 0
    for i in range(N):
        cnt = format(bit&F[i], 'b').count('1')
        money += P[i][cnt]
    ans = max(money, ans)
 
print(ans)

Submission status: Accepted

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

ans = -10**9
for i in range(1, 2**10):
    open = []
    for j in range(10):
        if ((i>>j) & 1):
            open.append(1)
        else:
            open.append(0)
    money = 0
    for num in range(N):
        Flist = Flists[num]
        same = sum([int(open[_] and Flist[_]) for _ in range(10)])
        money += Plists[num][same]
    ans = max(ans, money)

print(ans)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
# sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def main():
    N = I()
    F = []
    P = []

    for i in range(N):
        F.append(LI())

    for i in range(N):
        P.append(LI())

    M = 10
    ans = - (10 ** 19)

    for i in range(2 ** M):
        f = []
        for j in range(M):
            if ((i >> j) & 1):
                f.append(1)
            else:
                f.append(0)

        if not any(f):
            continue

        profit = 0
        for j in range(N):
            c = 0
            for k in range(10):
                if f[k] == 1 and F[j][k] == 1:
                    c += 1
            # print(c, P)
            profit += P[j][c]
        ans = max(ans, profit)
        # print(f)

    print(ans)

if __name__ == '__main__':
    main()

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

c=list(itertools.product([0,1], repeat=10))
c.pop(0)

ans=-10**10
for joisino in c:
    SUM=0
    count=[0]*N
    for i in range(10):
        if joisino[i]==1:
            for g in range(N):
                if F[g][i]==1:
                    count[g]+=1
    for m in range(N):
        SUM+=P[m][count[m]]
    ans=max(ans,SUM)
print(ans)

Submission status: Accepted

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

def main():
  n = int(input())
  fs = []
  ps = []
  for _ in range(n):
    f = sum([v * (2**i) for i, v in enumerate(map(int, input().split()))])
    fs.append(f)
    
  for _ in range(n):
    p = list(map(int, input().split()))
    ps.append(p)
    
  max = -10**10    
  for x in range(1, 2**10):
    score = 0
    for i, f in enumerate(fs):
      c = bin(x & f).count('1')
      score += ps[i][c]
    if score > max:
      max = score
  print(max)

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
N = int(input())
Flists = [list(map(int, input().split())) for _ in range(N)]
Plists = [list(map(int, input().split())) for _ in range(N)]
ans = -10**9
for i in range(1, 2**10):
    open = []
    for j in range(10):
        if ((i >> j) & 1):
            open.append(1)
        else:
            open.append(0)
    money = 0
    for num in range(N):
        Flist = Flists[num]
        same = sum([int(open[_] and Flist[_]) for _ in range(10)])
        money += Plists[num][same]
    ans = max(ans, money)
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)]

outcome_list = []
for i in range(1, 1 << 10):
    outcome = 0
    for f, p in zip(F, P):
        n_store = "{:010b}".format(i & f).count("1")
        outcome += p[n_store]
    outcome_list.append(outcome)
print(max(outcome_list))

Submission status: Accepted

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

outcome_list = []
for i in range(1, 1 << 10):
    outcome = 0
    for j, x in enumerate(f):
        both = "{:010b}".format(i & int(x, 2))
        n_store = sum(map(int, list(both)))
        outcome += p[j][n_store]
    outcome_list.append(outcome)
print(max(outcome_list))

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 j in range(N)]  
m = -9999999999  
for i in range(1, 2**10):
    s = 0
    for j in range(N):
        count = 0
        for k in range(10):
            if ((i >> k)&1) == 1 and F[j][k] == 1:
                count += 1
        s += P[j][count]
    m = max(m, s)  
print(m)

Submission status: Accepted

Solution code:
n = int(input())
f = [[0]*10 for _ in range(n)]
p = [[0]*11 for _ in range(n)]
wa = [0]*10
ans = -1000000000000000000000000

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

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

for i in range(2**10):
    if i == 0:
        continue
    pk = 0
    ls = [0,0,0,0,0,0,0,0,0,0]
    for j in range(10):
        if (i >> j) & 1:
            ls[j] = 1
        
    for k in range(n):
        o = 0
        for l in range(10):
            if f[k][l] == 1 and ls[l] == 1:
                o += 1
                
        pk += p[k][o]
        
    ans = max(ans,pk)
    
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=-float('inf')
for i in range(1,2**10):
    tmp=list(map(int,list(format(i, '010b'))))
    p_tmp=[0 for _ in range(n)]
    for i in range(n):
        cnt=0
        for j in range(10):
            if tmp[j]==1 and f[i][j]==tmp[j]:
                cnt+=1
        p_tmp[i]=cnt
    P=0
    for k in range(n):
        P+=p[k][p_tmp[k]]
    ans=max(ans,P)
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 = -10000000000
for i in range(1, 2**10):
    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if((i>>k)%2 == 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= [list(map(int, input().split())) for _ in range(N)]
P= [list(map(int, input().split())) for _ in range(N)]

ans = -10000000000
for mask in range(1, 2**10):
    tmp = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if((mask>>k)%2 == 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 = [list(map(int,input().split())) for _ in range(n)]
p = [list(map(int,input().split())) for _ in range(n)]
mise = []

ans = -10**9

for i in range(1,2 ** 10):
	kari = []
	ii = i
	for j in range(10):
		kari.append(ii%2)
		ii = ii//2	
	mise.append(kari)

mise.pop(0)

for i in range(len(mise)):
	rieki = 0
	for j in range(n):
		counter = 0
		for k in range(10):
			counter += f[j][k]*mise[i][k]
		rieki += p[j][counter]
	ans = max(rieki,ans)
		
print(ans)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

INF = 10**9

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 = -INF
for i in range(1,1<<10):
    tmp = 0
    for j in range(N):
        b_hours = 0
        for k in range(10):
            if i&(1<<k) and F[j][k]:
                b_hours += 1
        tmp += P[j][b_hours]
    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)]
ans = -float('inf')

o = []
for i in range(2 ** 10):
    op = [0] * 10
    for j in range(10):
        if ((i >> j) & 1):
            op[9-j] = 1
    o.append(op)
o.remove([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
for openinfo in o:
    #openinfo = [0, 1, 0, 0, 0, 1, 0, 0, 1, 0]
    tmp = 0
    for i in range(n):
        cnt = 0
        for j in range(10):
            if openinfo[j] == 1 and f[i][j] == 1:
                cnt += 1
        tmp += p[i][cnt]
    ans = max(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
#080_C
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**9

for i in range(1,2**10):
    l=[]
    for j in range(10):
        if (i>>j)&1:
            l.append(1)
        else:
            l.append(0)
    res=0       
    for j in range(n):
        res+=p[j][sum([f[j][k]*l[k] for k in range(10)])]
    ans=max(ans,res)
    
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 = - float('inf')
for flag in range(1, 2 ** 10):  # 開店スケジュールでループを回す。ただし開店しないことはない。
    tmp = 0
    for shop in range(n):  # 他店の開店数に対応
        op = 0  # 初期値は0でしまっている
        for i in range(10):  # 曜日と時間に対応
            if flag & (1 << i):  # 論理積をとって1が立っている時
                c = 1  # 開店
            else:
                c = 0  # 閉店
            if F[shop][i] * c == 1:  # そもそも新規店舗が空いていない時はc=0で、対象の店が空いていない時はF[][]=0になる
                op += 1  # 両方開店している時
        tmp += P[shop][op]  # 利益を足す
    ans = max(ans, tmp)  # 最大値を更新
print(ans)

Submission status: Accepted

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

result = []
for i in range(1, 2**10):
    b = format(i, "010b")
    r = 0
    for j in range(n):
        c = [1 for I in range(10) if b[I]==f[j][I]=="1"]
        r += p[j][len(c)]
    result.append(r)
print(max(result))

Submission status: Accepted

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

result = []
for i in range(1, 2**10):
    b = format(i, "010b")
    r = 0
    for j in range(n):
        c = 0
        for s in range(10):
            if b[s]=="1" and f[j][s]=="1":
                c += 1
        r += p[j][c]
    result.append(r)
print(max(result))

Submission status: Accepted

Solution code:
import sys
import numpy as np

input = sys.stdin.readline

# N 店の数
n = int(input())

# F 店の営業計画
f = [input().replace(" ", "") for i in range(n)]

# P 営業利益
p = [list(map(int, input().split())) for i in range(n)]

# 全ての時間帯で店を開けるか閉めるの組合せを考える。
# 2 ** 10 の組合せで最大の利益となるものを求める
p_max = -999999999999999
# 1日は開ける必要があるので 1から
for i in range(1, 1024):
    # 2進数にして 1：店を開ける 0：店を開けない
    f_b = format(i, '010b')
    # 10個の時間帯１パターンでの最大利益
    p_10 = 0
    for f_1, p_1 in zip(f, p):
        # 店１つ分の処理
        # お姉ちゃんの店と同時に開いている回数
        p_cnt = 0
        for j in range(10):
            # 10個の時間帯ごとの処理
            if f_1[j] == '1' and f_b[j] == '1':
                # 両方の店が開いている
                p_cnt += 1
        # 両方で営業している回数での利益
        p_10 += p_1[p_cnt]
    if p_10 > p_max:
        # 利益が大きいので入れ替え
        p_max = p_10

print(p_max)

Submission status: Accepted

Solution code:
N=int(input())
F=[int(input().replace(" ",""),2) for i in range(N)]
P=[list(map(int,input().split())) for i in range(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:
#!/usr/bin/env PyPy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7
import itertools

def main():
    N=I()
    F=[[] for _ in range(N)]
    P=[[] for _ in range(N)]
    
    for i in range(N):
        F[i]=LI()
        
    for i in range(N):
        P[i]=LI()
    
    def calc(L):
        temp=0
        for i in range(N):
            cnt=0
            for j in range(10):
                cnt+=L[j]*F[i][j]
            temp+=P[i][cnt]
            
        return temp
    
    ans=-1*(10**10)
    for ite in itertools.product([0,1], repeat=10):
        if sum(ite)!=0:
            ans=max(ans,calc(ite))

    print(ans)

main()

Submission status: Accepted

Solution code:
n = int(input())
f = []
for i in range(n):
	ff = list(map(int, input().split()))
	f.append(ff)
p = []
for i in range(n):
	pp = list(map(int, input().split()))
	p.append(pp)
ans = -10**10
for i in range(1, 2**10):
	tmp = 0
	for j in range(n):
		c = 0
		for k in range(10):
			if (i >> k) & 1 and f[j][k] == 1:
				c += 1
		tmp += p[j][c]
	ans = max(ans, tmp)
print (ans)

Submission status: Accepted

Solution code:
n = int(input())
f = []
a = ["0","1"]
for i in range(n):
	ff = list(map(int, input().split()))
	f.append(ff)

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

def calc(t):
	y = list(t)
	tmp = 0
	flg = False
	for k in range(n):
		c = 0
		for b in range(10):
			if y[b] == "1" and f[k][b]:
				c += 1
				flg = True
		tmp += p[k][c]
	if flg == True:
		return tmp
	else:
		return -10**10

x = []
def dfs(i, s):
	for j in a:
		if i == 10:
			x.append(calc(s))
			return
		else:
			dfs(i+1, s+j)
dfs(0, "")
print (max(x))