Problem:


Score : 300 points

Problem Statement

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

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

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

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

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

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

Constraints

1≤N≤100

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

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

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

All input values are integers.

Input

Input is given from Standard Input in the following format:

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

Output

Print the maximum possible profit of Joisino's shop.

Sample Input 1

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

Sample Output 1

8

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

Sample Input 2

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

Sample Output 2

-2

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

Sample Input 3

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

Sample Output 3

23



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


Sample output:
8

Submission status: Accepted

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

ans = -10000000000
for i in range(1,1024):
    b = []
    a = 0
    for j in range(10):
        if i | (2**j) == i:
            b.append(1)
        else:
            b.append(0)
    for j in range(n):
        count = 0
        for k in range(10):
            if b[k] == 1 and f[j][k] == 1:
                count += 1
        a += p[j][count]
    ans = max(a,ans)
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)]


l = []

for i in range(1, 1024):
    a = format(i, '010b')
    b = list(a)
    l.append(b)

ans = 0

for i in range(n):
    y = 0

    for j in range(10):
        if l[0][j] == f[i][j] == '1':
            y += 1
    ans += p[i][y]

for x in l:
    z = 0

    for i in range(n):
        y = 0

        for j in range(10):
            if x[j] == f[i][j] == '1':
                y += 1
        z += p[i][y]
    ans = max(ans, z)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = float("-INF")
f = [[0 for i in range(10)] for i in range(n)]
p = [[0 for i in range(11)] for i in range(n)]
for i in range(n):
  ft = list(map(int, input().split()))
  for j in range(10):
    f[i][j] = ft[j]
for i in range(n):
  pt = list(map(int, input().split()))
  for j in range(11):
    p[i][j] = pt[j]

for i in range(1, 2**10):
  t = 0
  for j in range(n):
    c = 0
    for k in range(10):
      if i>>k&1 and f[j][k]:
        c += 1
    t += p[j][c]
  ans = max(ans, t)
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())))

cand = []

def dfs(string, n, f, p):
    global cand
    if len(string) < 10:
        dfs(string + "f", n, f, p)
        dfs(string + "t", n, f, p)
    else:
        tf = list(string)
        booltf = []
        for i in range(10):
            if tf[i] == "t":
                booltf.append(True)
            else:
                booltf.append(False)
        #print(booltf)
        c = []
        c_sum = []
        for kth in range(N):
            c = [i*j for i,j in zip(booltf, F[kth])]
            c_sum.append(sum(c))
        
        profit = 0
        for i,c in zip(range(N), c_sum):
            profit += P[i][c]
            
        cand.append(profit)
        
        if len(cand) == 2**10:        
            ans = max(cand[1:])
            
            print(ans)

        

dfs("", N, F, P)

Submission status: Accepted

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

Submission status: Accepted

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

INF = float('inf')
ans = -INF
for b in range(1,2**10):
    tmp = 0
    for f,p in zip(fs,ps):
        c = 0
        for k in range(10):
            if b&(1<<k)==0: continue
            if f[k]: c += 1
        tmp += p[c]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
ans=-10**9
s=["".join(list(input().split())) for i in range(N)]
t=[list(map(int,input().split())) for i in range(N)]
for j in range(1,1024):
    q=0
    for i in range(len(s)):
        q+=t[i][(bin(int(s[i],2)&j)).count("1")]
    ans=max(ans,q)
print(ans)

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 = [[int(x) for x in input().split()] for _ in range(N)]
P = [[int(x) for x in input().split()] for _ in range(N)]
res = -10000000000
for b in range(1,1024):
    profit = 0
    for i in range(N):
        c = 0
        for j in range(10):
            if (b >> j) % 2 == 1 and F[i][j] == 1:
                c += 1
        profit += P[i][c]
    res = max(res, profit)
print(res)

Submission status: Accepted

Solution code:
from itertools import product

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')
t = [0, 1]
for store in product(t, t, t, t, t, t, t, t, t, t):
    if sum(store) == 0:
        continue

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

Submission status: Accepted

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


ans = -999999999999999999
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 f[i][x] == 1:
                cou += 1
        fund += p[i][cou]
    ans = max(ans, fund)

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)]
max_res = -10**9

me_list = list(itertools.product([0, 1], repeat=10))
for i in range(1, 2**10):
    res = 0
    co = [ 0 for o in range(N)]
    for j in range(10):
        if me_list[i][j] == 1:
            for k in range(N):
                co[k] += F[k][j]
    for j in range(N):
        res += P[j][co[j]]
    if res > max_res:
        max_res = res
            
print(max_res)

Submission status: Accepted

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

import itertools

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

# 重複順列で自分の店の全パターンを出す
me_list = list(itertools.product([0, 1], repeat=10))

# 初期値は利益の最小値
me_p = -float("inf")
# 自分の店の全パターンループ
for i in range(len(me_list)):

    # 一度も営業しないパターンを除く
    if i == 0:
        continue

    tmp_p = 0
    # 他店の数でループ
    for j in range(N):

        cnt = 0
        # 月～金のAMPMループ
        for k in range(10):

            # 他店との営業重複カウント
            if me_list[i][k] == 1 and F[j][k] == 1:
                cnt += 1
        
        # 各店舗との重複数に応じた利益を合算していく
        tmp_p += P[j][cnt]

    # 合算した利益を現状の最高値と比較して置き換えていく
    me_p = max(me_p, tmp_p)   

print(me_p)

Submission status: Accepted

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

import itertools

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

# 重複順列で自分の店の全パターンを出す
me_list = list(itertools.product([0, 1], repeat=10))

# 初期値は利益の最小値
me_p = -1000000000
# 自分の店の全パターンループ
for i in range(len(me_list)):

    # 一度も営業しないパターンを除く
    if i == 0:
        continue

    tmp_p = 0
    # 他店の数でループ
    for j in range(N):

        cnt = 0
        # 月～金のAMPMループ
        for k in range(10):

            # 他店との営業重複カウント
            if me_list[i][k] == 1 and F[j][k] == 1:
                cnt += 1
        
        # 各店舗との重複数に応じた利益を合算していく
        tmp_p += P[j][cnt]

    # 合算した利益を現状の最高値と比較して置き換えていく
    me_p = max(me_p, tmp_p)   

print(me_p)

Submission status: Accepted

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

import itertools

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

# 重複順列で自分の店の全パターンを出す
me_list = list(itertools.product([True, False], repeat=10))

# 初期値は利益の最小値
me_p = -float("inf")
# 自分の店の全パターンループ
for i in range(len(me_list)):

    # 一度も営業しないパターンを除く
    if not any(me_list[i]):
        continue

    tmp_p = 0
    # 他店の数でループ
    for j in range(N):

        cnt = 0
        # 月～金のAMPMループ
        for k in range(10):

            # 他店との営業重複カウント
            if me_list[i][k] and F[j][k]:
                cnt += 1
        
        # 各店舗との重複数に応じた利益を合算していく
        tmp_p += P[j][cnt]

    # 合算した利益を現状の最高値と比較して置き換えていく
    me_p = max(me_p, tmp_p)   

print(me_p)

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

max_gain = -float('inf')
for status in itertools.product([True, False], repeat=10):
    if not any(status):
        continue
    gain = 0
    for i in range(n):
        same_time_cnt = 0
        for j in range(10):
            if status[j] and f[i][j]:
                same_time_cnt += 1
        gain += p[i][same_time_cnt]
    max_gain = max(max_gain, gain)
print(max_gain)

Submission status: Accepted

Solution code:
N = int(input())
f = []
for i in range(N):
    raw = int(''.join(input().split()),2)
    f.append(raw)
p = []
for i in range(N):
    raw = list(map(int,input().split()))
    p.append(raw)
def lapCount(n,m):
    return bin(n&m).count("1")
ans = -1000000001
for state in range(1,1024):
    cand = 0
    for i in range(N):
        c = lapCount(state,f[i])
        cand += p[i][c]
    ans = max(ans,cand)
print(ans)

Submission status: Accepted

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

max_ans = -float("inf")

for i in range(1, 1024):
	ans = 0
	for j in range(n):
		ans += P[j][list(str(bin(i & F[j]))).count("1")]
	if ans > max_ans:
		max_ans = ans

print(max_ans)

Submission status: Accepted

Solution code:
from itertools import product
N=int(input().strip())
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())))
# 2**10で間に合う
score=-float('inf')
opt=0
for op in product(*[(0,1) for i in range(10)]):
    if sum(op)==0:
        continue
    sc=0
    for n in range(N):
        c=sum(F[n][i] and op[i] for i in range(10))
        sc+=P[n][c]
    if score<sc:
        score=sc
        opt=op
print(score)

Submission status: Accepted

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

    cost = []
    for i in range(1,2**10):
        cost_i = 0
        k = i
        now = ""
        for _ in range(10):
            now += str(k%2)
            k = k//2
        for n in range(N):
            ci = 0
            for j in range(10):
                if int(now[j])==F[n][j]==1:
                    ci += 1
            cost_i += P[n][ci]
        cost.append(cost_i)

    return max(cost)

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

Submission status: Accepted

Solution code:
N = int(input())
F = []
P = []
ans = -10**9
def cal_same_num(F,temp):
    num_same = 0
    for i in range(10):
        if temp[i] == "1" and F[i] == 1:
            num_same += 1
    return num_same

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

for i in range(1,2**10):
    sum_point = 0
    temp = str(format(i,"b")).zfill(10)
    for j in range(N):
        num_same = cal_same_num(F[j],temp)
        point = P[j][num_same]
        sum_point += point
    ans = max(ans,sum_point)
print(ans)

Submission status: Accepted

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

n = int(input())
F = [list(map(int, input().split())) for _ in range(n)]
P = [list(map(int, input().split())) for _ in range(n)]
ans = -1e10

for sister in range(1, 1024):
    count = 0
    for i in range(n):
        cost_list = list('{:b}'.format(int(''.join(map(str, F[i])), 2) & sister))
        cost = 0
        for j in range(len(cost_list)):
            cost += int(cost_list[j])
        count += P[i][cost]
    ans = max(ans, count)

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

MAX_ans = pow(10,9)*(-1)
for K in range(1,1024):
    C = [0 for i in range(N)]
    c = 0
    while(K>0):
        if K%2==1:
            for j in range(N):
                if F[j][c] == 1: C[j] += 1
        c += 1
        K //=2
    ans = 0
    for j in range(N):
        ans += P[j][C[j]]
    if ans > MAX_ans: MAX_ans = ans

print(MAX_ans)

Submission status: Accepted

Solution code:
from itertools import product

N = int(input())
F = []
P = []
for _ in range(N):
    temp = list(map(int, input().split()))
    F.append([temp[:2], temp[2:4], temp[4:6], temp[6:8], temp[8:]])
for _ in range(N):
    P.append(list(map(int, input().split())))

prod = list(product((0, 1), (0, 1), (0, 1), (0, 1), (0, 1),
                    (0, 1), (0, 1), (0, 1), (0, 1), (0, 1)))
MAX = -float("inf")


def compute(pattern):
    x = 0
    for i in range(N):
        c = 0
        for j in range(5):
            for k in range(2):
                if pattern[j][k] == 1 and F[i][j][k] == 1:
                    c += 1
        x += P[i][c]
    return x


del prod[0]
for e in prod:
    pattern = [e[:2], e[2:4], e[4:6], e[6:8], e[8:]]
    MAX = max(compute(pattern), MAX)

print(MAX)

Submission status: Accepted

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

max_p = float('-inf')
for i in range(1,1024):
    p = 0
    for j in range(len(F_list)):
        c = format(i & F_list[j], 'b').count('1')
        p += P_list[j][c]
    if p > max_p:
        max_p = p
print(max_p)

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

c = product([0,1],repeat=10)
profits = []

for i in c:
    i = list(i)
    if sum(i) == 0:
        continue
    Duplist = []
    profit = 0
    for j in range(N):
        shop = F[j]
        Dup = 0
        for i_,k in enumerate(shop):
            if i[i_] == 1 and k == 1:
                Dup += 1
        Duplist.append(Dup)
    for i_,j in enumerate(Duplist):
        profit += P[i_][j]
    profits.append(profit)
    
print(max(profits))

Submission status: Accepted

Solution code:
import numpy as np
from itertools import product

N = int(input())
F = np.array([list(map(int, input().split())) for i in range(N)])
P = np.array([list(map(int, input().split())) for i in range(N)])
O = list(product([0, 1], repeat=10))
del O[0]
O = np.array(O)
ans = -float('inf')
for o in O:
    tmp = 0
    OF = F*o
    K = []
    for of in OF:
        K.append(np.count_nonzero(of, axis=0))
    for i in range(N):
        tmp += P[i][K[i]]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
eigyo = []
for i in range(N):
    eigyo.append(list(map(int, input().split())))
uriage = []
for i in range(N):
    uriage.append(list(map(int, input().split())))
# print(eigyo)
# print(uriage)

def get_kaburi(decide, i):
    kaburi = 0
    for j in range(10):
        if (decide[j] == 1) and (eigyo[i][j] == 1):
            kaburi += 1
    return kaburi

infinity = 10**10

def get_score(decide):
    if sum(decide) == 0:
        return -infinity
    score = 0
    total_kaburi = 0
    for i in range(N):
        kaburi = get_kaburi(decide, i)
        score += uriage[i][kaburi]
    return score

scores = map(get_score, itertools.product([0,1], repeat=10))
print(max(scores))

Submission status: Accepted

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

ans = 0
first = True

def get_list(x):
    l = []
    for i in range(10):
        l.append(x%2)
        x//=2
    return l

for z in range(1, 2**10):
    l = get_list(z)
    p = 0
    c = 0
    for i in range(n):
        c = 0
        for j, x in enumerate(l):
            if x == 0:
                continue
            if runs[i][j] == 1:
                c += 1
        p += points[i][c]
    if first:
        ans = p
        first = False
    else:
        ans = max(ans, p)
print(ans)

Submission status: Accepted

Solution code:
# def makelist(n, m):
#     return [[0 for i in range(m)] for j in range(n)]

N = int(input())
F = [0]*N
P = [0]*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()))


def calc(lst):
    res = 0
    for n in range(N):
        cnt = 0
        for i in range(10):
            if lst[i] + F[n][i] == 2:
                cnt += 1
        res += P[n][cnt]
    return res

def func(acc):
    if len(acc) == 10:
        if 1 in acc:
            return calc(acc)
        else:
            return -2e9
    else:
        return max(func(acc + [0]), func(acc + [1]))

print(func([]))

Submission status: Accepted

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

for i in range(1,1024):
    tmp = 0
    for j in range(N):
        count = 0
        for k in range(10):
            if ((i>>k)&1)&F[j][k]:
                count+=1
        tmp+=P[j][count]
    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=[]
for k in range(2**10,2**11):
    a=[]
    t = [0 for x in range(n)]
    s = bin(k)[3:]
    for i in range(10):
        if s[i]=='1':
            for j in range(n):
                if f[j][i]==1:
                    t[j]+=1
    if max(t)!=0:
        a = [p[i][t[i]] for i in range(n)]
        ans.append(sum(a))
print(max(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 b in range(1,2**10):
    tmp = 0
    for i in range(N):
        c = 0
        for k in range(10):
            if b&(1<<k) and F[i][k]:
                c += 1
        tmp += P[i][c]
    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_2=-float("inf")
for i in range(1,1<<10):
    ans=0
    for k in range(n):
        cnt=0
        for j in range(10):
            if i&(1<<j) and f[k][j]==1:
                cnt+=1
        ans+=p[k][cnt]
    ans_2=max(ans,ans_2)
print(ans_2)

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

Submission status: Accepted

Solution code:
N = int(input())
F = [list(map(int, input().split())) for k in range(N)]
P = [list(map(int, input().split())) for k in range(N)]
B = [format(k,'b').zfill(10) for k in range(1,1024)]
ans = -10**9

for d in B:
    t = 0
    E = [0 for k in range(N)]
    for l in range(N):
        for k in range(10):
            E[l] += int(d[k])*F[l][k]
    for k in range(N):
        t += P[k][E[k]]
    ans = max(t,ans)

print(ans)

Submission status: Accepted

Solution code:
def max_profit(num, time1, time2, pro, idx):
    if idx == 10:
        if time1 == [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]:
            return -1000000000

        prof = 0
        for i in range(num):
            cnt = 0
            for j, k in zip(time1, time2[i]):
                if j == 1 and j == k:
                    cnt += 1
            prof += pro[i][cnt]

        return prof

    time3 = time1.copy()
    p1 = max_profit(num, time3, time2, pro, idx+1)
    time3[idx] = 1
    p2 = max_profit(num, time3, time2, pro, idx+1)

    return max(p1, p2)


n = int(input())
t = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for j in range(n)]
t1 = [0 for k in range(10)]
print(max_profit(n, t1, t, p, 0))

Submission status: Accepted

Solution code:
from itertools import compress

def main():
    N = int(input())
    F = tuple(tuple(map(int, input().split())) for _ in [0] * N)
    P = tuple(tuple(map(int, input().split())) for _ in [0] * N)

    profits = -float('inf')
    mask = 1
    while mask < (1 << 10):
        n = 0
        sel = list(map(int, format(mask, '010b')))
        for i, f in enumerate(F):
            j = sum(compress(f, sel))
            n += P[i][j]
        profits = max(profits, n)
        mask += 1

    print(profits)

main()

Submission status: Accepted

Solution code:
N = int(input())

F,P,b,T = [],[],1,-9999999999

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

while b < 1 << 10:
    bs = "{0:10b}".format(b)
    bsi = 0
    S = [0]*N
    for c in bs:
        if c == "1":
            for i in range(N):
                S[i] += F[i][bsi]
        bsi += 1
    t = 0
    for i in range(N):
        t += P[i][S[i]]
    if T < t:
        T = t
    b += 1
print(T)

Submission status: Accepted

Solution code:
def ans():
    tmp = -9999999999999
    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)]

    def calculate(B):
        v = []
        for n in range(N):
            mcnt = 0
            for k in range(10):
                if B[k] == '1' and F[n][k] == 1:
                    mcnt += 1
            v.append(P[n][mcnt])
        return sum(v)

    for i in range(1, 1 << 10):
        bi = bin(i)
        bi = bi[2:]
        bi = '0' * (10 - len(bi)) + bi
        tmp = max(tmp, calculate(bi))
    return print(tmp)


ans()

Submission status: Accepted

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

l = []
ans = -10000000000000000000000000000
def f(now, i):
  if i >= 10:
    l.append(list(now))
    return
  
  f(now+"1", i+1)
  f(now+"0", i+1)
f("", 0)

for i in range(len(l)-1):
  temp = 0
  for j in range(len(shops)):
    count = 0
    for k in range(10):
      if shops[j][k] == "1" and l[i][k] == "1":
        count += 1
    temp += int(profits[j][count])
  if temp > ans:
    ans = temp

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
H=['']*N
W=['']*N
x=[]
for i in range(N):
    H[i]=list(map(int,input().split()))
for j in range(N):
    W[j]=list(map(int,input().split()))
for k in range(1,1024):
    t=[]
    for ii in range(10):
        if k&(1<<ii):
            t+=[1]
        else:
            t+=[0]
    ans=0
    for jj in range(N):
        s=0
        for kk in range(10):
            s+=H[jj][kk]*t[kk]
        ans+=W[jj][s]
    x.append(ans)
print(max(x))

Submission status: Accepted

Solution code:

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

result = -float("inf")

# opening schedule for my shop.
# start from 1(only open Mon.AM) to 1023(open all day)
for b in range(1, 1<<10):

    profit = 0
    # compare with other shops
    for i in range(n):

        common_opening = 0
        # compare time
        for j in range(10):

            if 1&(b>>j) and f[i][j] == 1:

                common_opening += 1
        profit += p[i][common_opening]

    result = max(result, profit)

print(result)

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C


# FIXME: More smarter.
def calc_benefit(my_schedule, others_schedule, benefit_table, answer):
    score = 0

    if sum(my_schedule) == 0:
        return benefit_total

    for index, other_schedule in enumerate(others_schedule):
        count = 0

        for mine, other in zip(my_schedule, other_schedule):
            if mine == other == 1:
                count += 1
        score += benefit_table[index][count]
    return max(score, benefit_total)


# FIXME: More smarter.
def dfs(my_schedule, others_schedule, benefit_table, benefit_total, pos):
    if pos == 10:
        return calc_benefit(my_schedule, others_schedule, benefit_table, benefit_total)

    my_schedule[pos] = 0
    foo = dfs(my_schedule, others_schedule, benefit_table, benefit_total, pos + 1)
    my_schedule[pos] = 1
    bar = dfs(my_schedule, others_schedule, benefit_table, benefit_total, pos + 1)
    return max(foo, bar)


if __name__ == '__main__':
    shop_count = int(input())
    others_schedule = [list(map(int, input().split())) for _ in range(shop_count)]
    benefit_table = [list(map(int, input().split())) for _ in range(shop_count)]

    benefit_total = -1000000000
    my_schedule = [None] * (10)

    # See: https://www.youtube.com/watch?v=GWhYUxeDe70
    benefit_total = dfs(my_schedule, others_schedule, benefit_table, benefit_total, 0)
    print(benefit_total)

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())))
#ビット探索
count=2**10
both=[0]*n
ans=-1000000000
profit=0
num=0#同時に出店した数を数える
for i in range(1023):
    count+=1
    bit=bin(count)
    for j in range(n):
        for k in range(10):
            if int(bit[k+3])&F[j][k]:#初め３桁は0b1が入っているので４桁目から
                num+=1
        profit+=P[j][num]   
        num=0           
    if profit>ans:
        ans=profit
    profit=0
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,1<<10):
    tot=0
    for k in range(n):
        bit=0
        for j in range(10):
            if i&(1<<j) and f[k][j]==1: bit+=1
        tot+=p[k][bit]
    ans=max(ans,tot)
print(ans)

Submission status: Accepted

Solution code:
from itertools import product

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


def main():
    open_count = [0 for i in range(N)]
    cnt = 0
    max_profit = - float('inf')

    for sister_store in list(product((0,1), repeat=10))[1:]:
        profit = 0
        for store_num in range(N):
            profit += calc_profit(sister_store, store_num)
        if profit > max_profit:
            max_profit = profit
    print(max_profit)

def calc_profit(sister, store_num):
    co_open = 0
    #print("store_num", store_num)
    for i in range(10):
        """
        print("{0:<10} {1:d}".format("sister :",sister[i]))
        print("{0:<10} {1:d}".format(" store :",F[store_num][i]))
        """
        co_open += sister[i] * F[store_num][i]

    return P[store_num][co_open]
main()

Submission status: Accepted

Solution code:
N=int(input())
bord=[[] for i in range(N)]
for i in range(N):
  bord[i]=[int(x) for x in input().split()]
sales=[[] for i in range(N)]
for i in range(N):
  sales[i]=[int(x) for x in input().split()]

ans=-100000000000
for i in range(1,2**10):
  res=0
  for j in range(N):
    cnt=0
    for k in range(10):
      if (i>>k)%2 and bord[j][k]==1:
        cnt+=1
    res+=sales[j][cnt]
  ans=max(res,ans)
print(ans)

Submission status: Accepted

Solution code:
import itertools
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)]
answer = -10**9
for i in itertools.product(range(2),repeat=10):
	if sum(i) != 0:
		num = 0
		for j in range(n):
			num2 = 0
			for k in range(10):
				num2 += i[k]*f[j][k]
			num += p[j][num2]
		if answer < num:
			answer = num
print(answer)