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 = [int(input()[::2], 2) for i in range(n)]
p = [list(map(int, input().split())) for l in range(n)]
ans = -float("inf")
for h in range(1, 1024):
    ans = max(ans, sum(p[g][sum(list(map(int, bin(f[g] & h)[2:])))] for g in range(n)))
print(ans)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
f = []
p = []
res = -10**100
for i in range(n):
    f.append(list(map(int,input().split())))
for i in range(n):
    p.append(list(map(int,input().split())))
l = [0,1]
q = list(itertools.product(l,repeat=10))
del q[0]
for i in q:
    r = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if i[k] and f[j][k]:
                c += 1
        r += p[j][c]
    res = r if res<r else res
print(res)

Submission status: Accepted

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

plist = []
for i in range(1,1024):
    plist.append(format(i,'010b'))

score = {}
for i in range(len(plist)):
    m = 0
    choice = plist[i]
    for j in range(N):
        count = 0
        for k in range(10):
            if choice[k] == F[j][k] == "1":
                count += 1
        m += P[j][count]
    score[i] = m

print(max(score.values()))

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

a     = []
count = 0
point = []
PP = []

for _ in range(2**10+1,2**10*2):
    a.append(list(map(int,list(bin(_)[3:]))))

for k in range(2**10-1):
    for i in range(n):
        for j in range(10):
            if f[i][j]&a[k][j] == 1:
                count += 1
        point.append(p[i][count])
        count = 0
    PP.append(sum(point))
    point = []
print (max(PP))

Submission status: Accepted

Solution code:
n=int(input())
f=[[[0for i in range(2)]for j in range(5)]for k in range(n)]
p=[[0for i in range(11)]for j in range(n)]
opn=[[0for i in range(2)]for j in range(5)]
maxi=-10**9
for i in range(n):
  l=list(map(int,input().split()))
  for j in range(5):
    f[i][j][0]=l[j*2]
    f[i][j][1]=l[j*2+1]
for i in range(n):
  p[i]=list(map(int,input().split()))
for i in range(1,2**10):
  s=bin(i)[2:].zfill(10)
  for j in range(10):opn[j//2][j%2]=int(s[j])
  ben=0
  for j in range(n):
    same=0
    for k in range(10):
      same+=opn[k//2][k%2]*f[j][k//2][k%2]
    ben+=p[j][same]
  maxi=max([maxi,ben])
print(maxi)

Submission status: Accepted

Solution code:
import numpy as np
l = 10
f = 2 ** l - 1
ans = -float("inf")
n = int(input())
def ch(n):
    if int(n) == 1:
        return 1
    else:
        return 2
j = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for j in range(n)])
for i in range(n):
    j[i] = (np.array(list(map(ch, input().split()))))
costs = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for j in range(n)])
for i in range(n):
    costs[i] = (np.array(list(map(int, input().split()))))
for i in range(2**l - 1):
    ff = np.array(list(map(int, list(format(f, "b").zfill(l)))))
    tmp = 0
    for h in range(n):
        tmp += costs[h][np.sum(ff == j[h])]
    ans = max(ans, tmp)
    f -= 1
print(ans)

Submission status: Accepted

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

import sys

u"""
1023回全て check
"""

def ones(n):
    o = 0
    for i in xrange(0, 10):
        b = 1 << i
        if n & b:
            o += 1
    return o

n = int(raw_input().split()[0])
# print n

openL = []
for _ in xrange(0, n):
    fs = ''.join( [e for e in raw_input().split()] )
    openL.append( int(fs, base=2) )
    
profL = []
for _ in xrange(0, n):
    profL.append( [int(e) for e in raw_input().split()] )

# print n
# print [hex(e) for e in openL]
# print profL, len(profL[0])

# print ones(0), ones(0x3ff)

maxP = -sys.maxint - 1
for i in xrange(1, 1024):
    p = 0
    for x in xrange(0, len(openL)):
        ox = openL[x]
        px = profL[x]
        p += px[ ones(ox & i) ]

    if p > maxP:
        maxP = p
    
sys.stdout.write('%d\n' % maxP)
sys.stdout.flush()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc080/tasks/abc080_c

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, F, P):
    max_profit = float('-inf')

    for i in range(1, 2**10):
        profit = 0
        opens = [int(x) for x in bin(i)[2:].zfill(10)]
        for shop in range(1, N+1):
            match = [1 for a, b in zip(opens, F[shop]) if a and b]
            m = sum(match)
            profit += P[shop][m]
        if profit > max_profit:
            max_profit = profit
    return max_profit


def main(args):
    # N = 3
    # F = [[]]
    # F.append([1, 1, 1, 1, 1, 1, 0, 0, 1, 1])
    # F.append([0, 1, 0, 1, 1, 1, 1, 0, 1, 0])
    # F.append([1, 0, 1, 1, 0, 1, 0, 1, 0, 1])
    # P = [[]]
    # P.append([-8, 6, -2, -8, -8, 4, 8, 7, -6, 2, 2])
    # P.append([-9, 2, 0, 1, 7, -5, 0, -2, -6, 5, 5])
    # P.append([6, -6, 7, -9, 6, -5, 8, 0, -9, -7, -7])

    N = int(input())
    F = [[]]
    P = [[]]
    for _ in range(N):
        F.append([int(x) for x in input().split()])
    for _ in range(N):
        P.append([int(x) for x in input().split()])
    ans = solve(N, F, P)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
count = int(input().rstrip())
shops = [input().split() for i in range(count)]
gain = [input().split() for i in range(count)]

 
max = -1000000000
for k in range(1,1024):
    tmp = format(k,'b').zfill(10)
    tmp_sum = 0
    for N in range(count):
        shop_count = 0
        for l in range(10):
            if tmp[l] == shops[N][l] and tmp[l] =='1':
                shop_count +=1
        tmp_sum += int(gain[N][shop_count]) 
    if max < tmp_sum:
        max = tmp_sum
 
print(max)

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

cost = -10**10
for a in itertools.product((0, 1), repeat=10):
    if a==(0, 0, 0, 0, 0, 0, 0, 0, 0, 0):
        continue
    tmp_cost = 0
    for i in range(N):
        tmp_c = 0
        l = 0
        for j in range(5):
            for k in range(2):
                tmp_c += F[i][l]*a[l]
                l += 1
        tmp_cost += P[i][tmp_c]
    cost = max(cost, tmp_cost)

print(cost)

Submission status: Accepted

Solution code:
#abc080c

n=int(raw_input())
f=[map(int,raw_input().split()) for i in xrange(n)]
p=[map(int,raw_input().split()) for i in xrange(n)]
res=-float('inf')
for i in xrange(1,1024):
 temp=0
 for j in xrange(n):
  cnt=0
  for k in xrange(10):
   cnt+=int(i>>k&1 and f[j][k])
  temp+=p[j][cnt]
 res=max(temp,res)
print res

Submission status: Accepted

Solution code:

def profit(xs, n, F, P):
    return sum([P[i][sum(map(lambda x: x[0]*x[1], zip(xs, F[i])))] for i in range(n)])


def vector(k):
    return [1 if k & 1 << i else 0 for i in range(10)]


def foo(n, F, P):
    return max([profit(vector(pat), n, F, P) for pat in range(1, 1024)])


if __name__ == "__main__":
    n = int(input())
    F = {}
    P = {}
    for i in range(n):
        F[i] = list(map(int, input().split()))
    for i in range(n):
        P[i] = list(map(int, input().split()))
        
    print(foo(n, F, P))

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=-1145141919810
for i in range(1023):
  i=bin(i+1 | 0b10000000000)
  i=str(i[3:])
  tmp=0
  for j in range(N):
    count=0
    for k in range(10):
      if int(i[k])==1 and F[j][k]==1:count+=1
    tmp+=P[j][count]
  if tmp>=res:res=tmp
print(res)

Submission status: Accepted

Solution code:
import math
import numpy as np
from operator import mul

# 整数Nを桁ごとのリストにする
# l = [int(x) for x in list(str(N))]

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(range(N))
max_p = -100**7-1

for i in range(1,2**10):
    i_bin = format(i, 'b').zfill(10)
    i_list = [int(x) for x in list(str(i_bin))]
    profit = 0 #それぞれの場合の利益を総当り
    for j in range(N):
        # 店jと同時に開いている時間の数を計算
        combine = map(mul, f[j], i_list)
        c[j] = sum(combine) # 0 <= c[j] <= 10
        profit += p[j][c[j]]
    if profit > max_p:
        max_p = profit

print(max_p)

Submission status: Accepted

Solution code:
N = input()
F = [map(int, raw_input().split()) for i in range(N)]
P = [map(int, raw_input().split()) for i in range(N)]
M = 10
ans = -10**10
for mask in range(1, 2**M):
    m = [int((mask & (2**i)) > 0) for i in range(M)]
    ok = False
    sales = 0
    for i in range(N):
        cnt = 0
        for j in range(M):
            if m[j] + F[i][j] == 2:
                ok = True
                cnt += 1
        sales += P[i][cnt]
    if ok:
        ans = max(ans, sales)
print ans

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
f = np.zeros((n, 10), dtype=np.int64)
p = np.zeros((n, 11), dtype=np.int64)

for i in range(n):
  tmp = list(map(int, input().split()))
  for j in range(10):
      f[i][j] = tmp[j]
for i in range(n):
  tmp = list(map(int, input().split()))
  for j in range(11):
    p[i][j] = tmp[j]

r = -1e18
for b in range(1, 1<<10):
  s = 0
  for i in range(n):
    c = 0
    for j in range(10):
      if (b >> j) & 1 == 1 and f[i][j]:
        c += 1
    s += p[i][c]
  if r < s:
    r = s

print(r)

Submission status: Accepted

Solution code:


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

ans = float("-inf")

for i in range(1,1 << 10):
  res=0
  for n in range(N):
    count=0
    for j in range(10):
      if i & F[n][j] << j: count+=1
    res+=P[n][count]
  ans=max(res,ans)
print(ans)

Submission status: Accepted

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

out = float('-inf')


for i in range(1,1024):
    b = 0
    for j in range(n):
        b += p[j][bin(f[j] & i).count('1')]
    out = max(b, out)
print(out)

Submission status: Accepted

Solution code:
import itertools
seq=('0','1')
a=list(itertools.product(seq, repeat=10))
n=int(input())

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

flg=0

z  = 0
z1 = -10000000000000
for ai0 in a:
  ai=[int(i) for i in ai0]
  z0=0

  if max(ai) > 0:
    for j in range(n):
      z0 += c[j][sum([x * y for x, y in zip(f[j], ai)])]

    if z0 > 0:
      z  = max(z,z0)
      flg=1
    else:  
      z1 = max(z1,z0)
    
if flg==0:
  print(z1)
else:
  print(z)

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 = None
for i in range(1, 1<<10):
    Fk = [[F[j][k] * ((i >> k) & 1) for k in range(10)] for j in range(N)]
    Cs = [sum(Fk[i]) for i in range(N)]
    s = sum([P[i][Cs[i]] for i in range(N)])
    if ans is None or ans < s:
        ans = s
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
     
f = [int(input().replace(" ", ""), 2) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
     
ans = float('-inf')
     
for i in range(1, 1024):
    price = 0
    for j in range(n):
        price += p[j][bin(i & f[j]).count('1')]
    ans = max(ans, price)
     
print(ans)

Submission status: Accepted

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

a = [i for i in range(10)]
combi = []
for i in range(10):
    combi.extend(list(itertools.combinations(a,i+ 1)))
#print(combi)

ans =  - float("inf")
for i in combi:
    #print(i)
    cnt = [0]*n
    for j in i:
        for k in range(n):
            cnt[k] += f[k][j]
    profit = sum([p[k][cnt[k]] for k in range(n)])
    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)]

def ev(lst):
    ret = 0
    for i in range(N):
        cnt = sum([1 if F[i][j] * lst[j] == 1 else 0 for j in range(10)])
        ret += P[i][cnt]
    return ret

NEG_INF = -100000000000000000000

def dfs(acc):
    if len(acc) == 10:
        if acc.count(1) == 0:
            return NEG_INF
        return ev(acc)

    lazy = max(dfs(acc + [0]), dfs(acc + [1]))
    return lazy

ans = dfs([])
print(ans)

Submission status: Accepted

Solution code:
# -*- Coding: utf-8 -*-
def sum_benefit(anded):
    summed= 0
    for shop in range(n_shop):
        summed += i_benefit[shop][anded[shop]]
    return summed

n_shop = int(input())
i_schedule = []
i_benefit = []


max_profit = 0

#開店スケジュールを2進数→10進数に変換
for i in range(n_shop):
    i_schedule.append(int(input().replace(" ",""),2))
    
for i in range(n_shop):
    i_benefit.append(list(map(int,input().split())))
    max_profit += min(i_benefit[i])
    
#全パターンの開店スケジューるの作成
#一つ以上の時間帯で店は開店しなければならない

#schedule=[format(i, '010b') for i in range(1,1024)]
schedule = [i for  i in range(1,1024)]

#そこから一致数の計算→リストのcountメソッドを使う
for sch in schedule:
    anded = []
    for j in range(n_shop):
        anded.append(format(sch & i_schedule[j], "b").count("1"))     #一致スケジュールを2進数表記にして，1の数を計算
        
    profit = sum_benefit(anded)
    
    if max_profit <= profit:
        max_profit = profit
    

print(max_profit)

Submission status: Accepted

Solution code:
from operator import mul
n = int(input())
cof = [1 << x for x in range(10)]

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

Submission status: Accepted

Solution code:

def binarize(txt):
    xs = txt.split(' ')
    xs = [int(x) for x in xs]
    b = 0
    for i in range(10):
        b += xs[i] * (2 ** i)
    return b


def count1(b):
    b = b[2:]
    count = 0
    for i in range(len(b)):
        if b[i] == '1':
            count += 1
    return count


N = input()
N = int(N)

F = [0 for i in range(N)]

for i in range(N):
    txt = input()
    F[i] = binarize(txt)


P = [[] for i in range(N)]

for i in range(N):
    xs = input().split(' ')
    P[i] = [int(x) for x in xs]


m = - 10 ** 11

for i in range(1, 2**10):

    score = 0

    for j in range(N):
        b = bin(i & F[j])
        count = count1(b)
        score += P[j][count]

    if score > m:
        m = score

print(m)

Submission status: Accepted

Solution code:
from logging import getLogger, basicConfig, DEBUG
basicConfig(level=DEBUG)
LOG = getLogger(__name__)

N = int(input())

def get_count_logical_and(base_int, list):
    result = []
    for item in list:
        logical_and = format(base_int & item, 'b').zfill(10)
        count = logical_and.count("1")
        result.append(count)
        # LOG.debug("{0} and {1} -> {2}".format(
        #     format(base_int, 'b').zfill(10), 
        #     format(item, 'b').zfill(10), 
        #     count))
    return result

def get_profits(pattern_array, lists):
    profits = 0
    for i in range(N):
        index = pattern_array[i]
        profit_list = lists[i]
        profits += profit_list[index]
        # LOG.debug("{0} : profits -> {1}".format(index, profits))
    return profits

def main():
    business_list = [int(input().replace(' ', ''), 2) for _ in range(N)]
    profits = [list(map(int, input().split())) for _ in range(N)]
    result = -float('inf')
    for i in range(1, 2 ** 10):
        open_pattern = get_count_logical_and(i, business_list)
        result = max(result, get_profits(open_pattern, profits))
        # LOG.debug("result -> {0}".format(result))
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = input()
s = list()
for i in xrange(1, 2**10):
    s.append(i)
time_table = list()
benefit = list()
for _ in xrange(n):
    time_table.append("".join(raw_input().split()))
for _ in xrange(n):
    benefit.append(list(map(int, raw_input().split())))

op = [[None for i in xrange(n)] for j in xrange(2**10-1)]
for i in xrange(n):
    for j in xrange(2**10-1):
        op[j][i] = sum(map(int, list(bin(s[j] & int(time_table[i],2))[2:])))

print max([sum([benefit[i][op[j][i]] for i in xrange(n)]) for j in xrange(2**10-1)])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

#print(F)
#print(P)

ans = -float('inf')
jkopen =  [[0 for j in range(5)] for k in range(2)]
for openday in range(1,1024):
    for j in range(5):
        for k in range(2):
            jkopen[k][j] = (openday & 2**(5*k+j))//2**(5*k+j)
    benefit = 0
#    print(jkopen)
    for shop in range(N):
        counter = 0
        for j in range(5):
            for k in range(2):
                counter += (jkopen[k][j] & F[shop][k+2*j])
        benefit += P[shop][counter]
#    print(counter)
    ans = int(max(ans,benefit))
print(ans)

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)]
t={i:0 for i in range(1,2**10)}
for i in range(1,2**10):
  d, b={j:0 for j in range(n)}, format(i, "010b")
  for j in range(n):
    for k in range(10):
      if (i>>k)%2&f[j][k]==1: d[j]+=1
    t[i]+=p[j][d[j]]
print(max(t.values()))

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


profit = float("-inf")

for i in range(1,1024):
	tmp = 0
	tmp2 = 0
	for j in range(N):
		tmp = (bin(i & F[j]).count('1'))
		tmp2 = tmp2 + P[j][tmp]
	profit = max(profit, tmp2)

print(profit)

Submission status: Accepted

Solution code:
n = int(input())
     
f = [int(input().replace(" ", ""), 2) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
     
ans = float('-inf')
     
for i in range(1, 1024):
    price = 0
    for j in range(n):
        price += p[j][bin(i & f[j]).count('1')]
    ans = max(ans, price)
     
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 = -1234567890
for mask in range(1,2**10):
    tmp = 0
    for i in range(n):
        cnt = 0
        for x in range(10):
            if (mask>>x) % 2 == 1 and f[i][x] == 1: cnt += 1
        tmp += p[i][cnt]
    ans = max(ans, tmp)
 
print(ans)

Submission status: Accepted

Solution code:
import sys

def main():
    line = sys.stdin.readline()
    n = int(line.rstrip())
    f = [None for i in range(n)]
    p = [None for i in range(n)]
    for i in range(n):
        line = sys.stdin.readline()
        f[i] = getFn([int(x) for x in line.rstrip().split(' ')])
        # print('f', i, f[i])
    for i in range(n):
        line = sys.stdin.readline()
        p[i] = [int(x) for x in line.rstrip().split(' ')]
    vMax = None
    for t in range(1, 1024):
        s = 0
        for i in range(n):
            common = countBit(f[i] & t)
            s += p[i][common]
        if vMax is None or vMax < s:
            vMax = s
    print(vMax)

def getFn(f):
    s = 0
    for b in f:
        s = (s << 1) | b
    return s

def countBit(c):
    s = 0
    while c > 0:
        if c & 1 == 1:
            s += 1
        c >>= 1
    return s

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations as comb
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)])
max_score = -10**7 * N - 1
d_arrN = list(range(N))
d_arr10 = list(range(10))
for i in range(10):
	for o_c in comb(d_arr10, i + 1):
		c_i = F[:, o_c].sum(axis=1)
		score = P[d_arrN, c_i].sum()
		max_score = max(max_score, score)
print(max_score)

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):
  res=0
  for n in range(N):
    count=0
    for j in range(10):
      if i & F[n][j]<<j: count+=1
    res+=P[n][count]
  ans=max(res,ans)
print(ans)

Submission status: Accepted

Solution code:
N = input()
F = []
P = []
for _ in xrange(N):
    F.append(map(int, raw_input().split()))
for _ in xrange(N):
    P.append(map(int, raw_input().split()))

calendar = [[]]
for _ in xrange(10):
    newCalendar = []
    for y in calendar:
        newCalendar.append(y + [0])
        newCalendar.append(y + [1])
    calendar = newCalendar
calendar.pop(0)

profits = []
for timeTable in calendar:
    currentProfit = 0
    for shopProfit, shopCalendar in zip(P, F):
        currentProfit += shopProfit[len([1 for (i, j) in zip(timeTable, shopCalendar) if i and j])]
    profits.append(currentProfit)
print max(profits)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    f = [LI() for _ in range(n)]
    p = [LI() for _ in range(n)]
    ii = [2**_ for _ in range(10)]
    r = -inf
    for k in range(1,2**10):
        a = [0] * n
        for i in range(10):
            if k&ii[i]:
                for j in range(n):
                    if f[j][i] == 1:
                        a[j] += 1
        tr = 0
        for i in range(n):
            tr += p[i][a[i]]
        if r < tr:
            r = tr

    return r



print(main())

Submission status: Accepted

Solution code:
count = int(input().rstrip())
shops = []
gain = []
for i in range(count):
    shops.append(input().rstrip().split())
for j in range(count):
    gain.append(input().rstrip().split())

max = -1000000000
for k in range(1,1024):
    tmp = format(k,'b').zfill(10)
    tmp_sum = 0
    for N in range(count):
        shop_count = 0
        for l in range(10):
            if tmp[l] == shops[N][l] and tmp[l] =='1':
                shop_count +=1
        tmp_sum += int(gain[N][shop_count]) 
    if max < tmp_sum:
        max = tmp_sum

print(max)

Submission status: Accepted

Solution code:
N = int(raw_input())
F = []
for n in range(N):
    F.append([int(val) for val in raw_input().split(" ")])
P = []
for n in range(N):
    P.append([int(val) for val in raw_input().split(" ")])

max_val = None
for i_X in xrange(1, 2**10):
    c_i = [0]*N
    for i_pos in range(10):
        X_ijk = (i_X/(2**i_pos))%2
        for i_n in xrange(N):
            c_i[i_n] += F[i_n][i_pos] * X_ijk
    score = sum([P[i_n][c_i[i_n]] for i_n in xrange(N)])
    if (type(max_val) == type(None)) or (score > max_val):
        max_val = score

print max_val

Submission status: Accepted

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

eigyo = []

b = []
Ci = []
for i in range(N):
    N_ = list(map(int, input().split()))
    eigyo.append(N_)
    Ci.append(sum(N_))

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


ans = -(1<<30)
a = list(map(lambda x: x*0, list(range(10))))
count = 0

def func():
    #score = 0
    global count
    count += 1
    #print(count, a)
    cc = 0
    if count!=1:
        for i in range(N):
            count_c = 0
            for j,element in enumerate(eigyo[i]):
                if element==a[j] and a[j]==1:
                    count_c += 1
            cc += P[i][count_c]
        global ans
        ans = max(ans, cc)
            
    #ans = max(ans, score)

def dfs(pos):
    if pos==10:
        func()
        return
    a[pos] = 0
    dfs(pos+1)
    a[pos] = 1
    dfs(pos+1)


dfs(0)
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

f, p, profits = [], [], []

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)

a = [0,1]

for x_ in itertools.product(a, repeat=10):
    x = list(x_)
    if sum(x) == 0:
        pass
    else:
        profit = 0
        for i, y in enumerate(f):
            count = 0
            for j,k in zip(x,y):
                if j == 1 and k == 1:
                    count += 1
            profit += p[i][count]
        profits.append(profit)

print(max(profits))

Submission status: Accepted

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

storeopen = [0,0,0,0,0,0,0,0,0,1]


maxmoney = None

while flag:
    money = 0
    for store in range(n):
        count = 0
        for i in range(10):
            if f[store][i] == 1 and storeopen[i] == 1:
                count += 1
        money += p[store][count]
    if maxmoney is None:
        maxmoney = money
    else:
        maxmoney = max(maxmoney, money)

    if sum(storeopen) == 10:
        flag = False
    else:
        storeopen[9] += 1
        for i in range(10):
            if storeopen[9-i] == 2:
                storeopen[9-i] = 0
                storeopen[8-i] += 1
print(maxmoney)

Submission status: Accepted

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

F=[]
P=[]

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

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

maxx=-1000000000001


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

Submission status: Accepted

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

F=[]
P=[]

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

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

maxx=-1000000000001

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

Submission status: Accepted

Solution code:
n = int(input())

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

ans = float('-inf')

for i in range(1, 1024):
    price = 0
    for j in range(n):
        price += p[j][bin(i & f[j]).count('1')]
    ans = max(ans, price)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools

def main():
    N = int(input())
    F_all = [[int(i) for i in input().split()] for _ in range(N)]
    P_all = [[int(i) for i in input().split()] for _ in range(N)]
    ans = float('-inf')
    for i in range(1, 11):
        # combinationsは第一引数の中から第二引数の文字数を使った組み合わせを返す．
        for iOPs in itertools.combinations(range(10), i):
            gain = 0
            for f, p in zip(F_all, P_all):
                c = sum(f[k] for k in iOPs)
                gain += p[c]
            ans = max(ans, gain)
    return ans


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

Submission status: Accepted

Solution code:
N = int(input())

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

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

ans = -float('inf')
for i in range(1, 1 << 10):
  profit = 0
  for j in range(N):
    a = i
    count = 0
    for k in range(10):
      count += a & shops[j][k]
      a >>= 1
    profit += profits[j][count]
  ans = max(ans, profit)

print(ans)