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

open_Shop=[]
for i in range(N):
    open_shop=list(map(int,input().split()))
    open_Shop.append(open_shop)
    
profit_List=[]
for i in range(N):
    profit_list=list(map(int,input().split()))
    profit_List.append(profit_list)
    

max_profit=(-1000000000)

sub_Array=[]
for i in range(1,1024):
    Num=i
    for j in range(10):
        sub_Array.append(Num//(2**(9-j)))
        Num%=2**(9-j)
    score=0
    profit=0
    for k in range(N):
        for l in range(10):
            score+=(open_Shop[k][l]*sub_Array[l])
        profit+=profit_List[k][score] 
        score=0
    if max_profit<profit:
        max_profit=profit
    sub_Array=[]
    #print(profit)
#print(sub_Array)
print(max_profit)

Submission status: Accepted

Solution code:
n = int(input())
F = [list(map(int,input().split())) for _ in range(n)]
P = [list(map(int,input().split())) for _ in range(n)]
res = -10**10

for bit in range(1, 1 << 10):
    a = [0 for _ in range(n)]
    for j in range(10):
        for i in range(n):
            if bit%2==1 and F[i][j]:
                a[i] += 1
        bit //= 2
    tmp = 0
    for i in range(n):
        tmp += P[i][a[i]]
    res = max(res, tmp)
print(res)

Submission status: Accepted

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

ans = -999999999999999
for i in range(1,1<<10):
    res = 0
    for j in range(N):
        cnt = 0
        for k in range(10):
            if ((i>>k)&1 == 1) and (F[j][k] == 1):
                cnt+=1
        res += P[j][cnt]
    ans = max(ans,res)
print(ans)

Submission status: Accepted

Solution code:
def openlist(i):
    S = format(i, "b")
    ret = [0] * 10
    for j, i in enumerate(reversed(range(len(S)))):
        ret[-1*(j+1)] = int(S[i])
    return ret


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

ans = -1 * 10 ** 9
for i in range(1, 2**10):
    S = openlist(i)
    # print(S)
    opstore = [sum([S[x]==1 and F[k][x]==1 for x in range(10)]) for k in range(n)]
    tmp_ans = sum([P[k][opstore[k]] for k in range(n)])
    ans = max(ans, tmp_ans)
print(ans)

Submission status: Accepted

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

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]

def dfs(cur:int, depth:int):
    if depth == 10:
        if cur == 0:
            return -float("inf")
        else:
            profit = 0
            for i,fi in enumerate(f):
                both = 0
                
                for mask in range(10):
                    if cur&(1<<mask) and fi&(1<<mask):
                        both += 1
                
                profit += p[i][both]
                
            return profit
    
    else:
        return max(dfs(cur+(1<<depth), depth+1),
                   dfs(cur, depth+1))
        
print(dfs(0,0))

Submission status: Accepted

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

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]

def dfs(cur:int, depth:int):
    if depth == 10:
        if cur == 0:
            return -float("inf")
        else:
            return sum([p[i][bin(cur&fi).count("1")] for i, fi in enumerate(f)])
    
    else:
        return max(dfs(cur+(1<<depth), depth+1),
                   dfs(cur, depth+1))
        
print(dfs(0,0))

Submission status: Accepted

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

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]

# bit全探索
ans = -float("inf")
for bit in range(1, 1<<10):
    profit = 0
    
    for i,fi in enumerate(f):
        both = 0
        
        for mask in range(10):
            if bit&(1<<mask) and fi&(1<<mask):
                both += 1
        
        profit += p[i][both]
    
    ans = max(ans, profit)
    
print(ans)

Submission status: Accepted

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

n = ni()
f = [int("".join(ls()), 2) for _ in range(n)]      
p = [list(li()) for _ in range(n)]

# bit全探索
ans = -float("inf")
for bit in range(1, 1<<10):
    profit = 0
    
    for i,fi in enumerate(f):
        both = bin(bit&fi).count("1")
        profit += p[i][both]
    
    ans = max(ans, profit)
    
print(ans)

Submission status: Accepted

Solution code:
N = input()
F = [map(int, raw_input().split()) for _ in range(N)]
P = [map(int, raw_input().split()) for _ in range(N)]
res = -float('inf')
for i in range(1, 2 ** 10):
  mask = '0' * (10 - len(bin(i)) + 2) + bin(i)[2:]
  cand = 0
  for j in range(N):
    c = 0
    for k in range(10):
      c += F[j][k] & int(mask[k])
    cand += P[j][c]
  res = max(res, cand)
print res

Submission status: Accepted

Solution code:

N = int(input())
farr = []
parr = []
for i in range(N):
    farr.append(list(map(int,input().split())))
for i in range(N):
    parr.append(list(map(int,input().split())))
paym = -10**10
count = 0
for i in range(1,1<<10):
    pay = 0
    for j in range(N):
        tmp = i
        for k in range(10):
            if farr[j][k] == 1 and (tmp//2**k)%2 == 1:
                count += 1
            if tmp == 0:
                break
        pay += parr[j][count]
        count = 0
        
    if pay > paym:
        paym = pay

print(paym)

Submission status: Accepted

Solution code:
def abc080_c():
    import numpy as np
    import itertools

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

    for i in range(1, 11):
        for seq in itertools.combinations([i for i in range(10)], i):
            tmp = 0
            for j in range(n):
                tmp += p[j][sum(f[j][np.array(seq)])]
            benefits = np.append(benefits, tmp)

    print(max(benefits))


abc080_c()

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

Submission status: Accepted

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

    res = -(1 << 30)
    for b in range(1, 1 << 10):
        p = 0
        for i in range(n):
            c = 0
            for j in range(10):
                if (b >> j) & 1 and fs[i][j]:
                    c += 1
            p += ps[i][c]
        if res < p:
            res = p

    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
f_list = []
p_list = []
ans_list = []
for i in range(n):
    f = list(map(int, input().split()))
    f_list.append(f)
for i in range(n):
    p = list(map(int, input().split()))
    p_list.append(p)
for i in range(1, 1<<10):
    ans = 0
    for j in range(n):
        count = 0
        for k in range(10):           
            if (i>>k & 1) == 1 and f_list[j][k] == 1:
                count += 1
        ans += p_list[j][count]
    ans_list.append(ans)
print(max(ans_list))

Submission status: Accepted

Solution code:
N = int(input())
F = []
P = []
for _ in range(N):
    F.append([int(f) for f in input().split()])
for _ in range(N):
    P.append([int(p) for p in input().split()])
res = []
for bit in range(1, 1 << 10):
    open_times = []
    for i in range(10):
        if((bit >> i) & 1) == 1:
            open_times.append(i)

    profit = 0
    for i in range(N):
        num_open = 0
        for open_time in open_times:
            if F[i][open_time]:
                num_open += 1
        profit += P[i][num_open]
    res.append(profit)

print(max(res))

Submission status: Accepted

Solution code:
N = int(input())
F = []
P = []
for _ in range(N):
    F.append([int(f) for f in input().split()])
for _ in range(N):
    P.append([int(p) for p in input().split()])
res = []
for bit in range(1, 1 << 10):
    open_times = []
    for i in range(10):
        if((bit >> i) & 1) == 1 and P:
            open_times.append(i)

    profit = 0
    for i in range(N):
        num_open = 0
        for open_time in open_times:
            if F[i][open_time]:
                num_open += 1
        profit += P[i][num_open]
    res.append(profit)

print(max(res))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input());r=range;F=[int(input()[::2],2)for _ in r(N)];P=[list(map(int,input().split(" ")))for _ in range(N)];print(max(sum(p[bin(i&f).count("1")]for f,p in zip(F,P))for i in r(1,1024)))

Submission status: Accepted

Solution code:
N=int(input());r=range;F=[int(input()[::2],2)for _ in r(N)];P=[list(map(int,input().split(" ")))for _ in range(N)]
print(max(sum(p[bin(i&f).count("1")]for f,p in zip(F,P))for i in r(1,1024)))

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

max_num = -(10**9)
for i in range(1, 1<<10):
    point = 0
    for j in range(N):
        point += P[j][bin(i&F[j]).count("1")]
    # print(point, end=", ")
    # if max_num < point:
    #     print(bin(i), point)
    max_num = max(max_num, point)

print(max_num)

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 = {}
ans = []
for bits in range(1 << 10):
    count = {}
    for i in range(10):
        if (bits >> i & 1) == 1:
            for j in range(n):
                if j not in count: 
                    count[j] = f[j][i]
                else:
                    count[j] += f[j][i]
    if count != {}:
        flag = 0
        for k in range(n):
            if count[k] != 0:
                flag = 1
        if flag:
            check = 0
            for l in range(n):
                check += p[l][count[l]]
            ans.append(check)
print(max(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 = -1000000000
for i in range(1, 1<<10):
	psum = 0
	for j in range(n):
		cnt = 0
		for k in range(10):
			if ((i>>k) & 1)==1 and f[j][k]==1:
				cnt += 1
		psum += p[j][cnt]
	ans = max(ans, psum)
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 j in range(n)]

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

L=[]
for m in range(1023):
  C=0
  for q in range(n):
    c=0
    for r in range(10):
      if f[q][r]*int(l[m][r])==1:
        c+=1
    C+=p[q][c]
  L.append(C)
print(max(L))

Submission status: Accepted

Solution code:
from itertools import product
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
ans = -float('inf')
for v in product([0, 1], repeat=10):
    if v.count(1) == 0:
        continue
    tmp = 0
    for i in range(n):
        c = 0
        for j in range(10):
            if v[j] == 1 and f[i][j] == 1:
                c += 1
        tmp += p[i][c]
    ans = max(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import math

N = int(input())

F = [None] * N
P = [None] * N

for i in range(N):
    F[i] = [x for x in input().split()]

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

def rieki(shopIdx, joisinoBit):
    binStr = "".join(F[shopIdx])
    shopBit = int(binStr,2)

    common = shopBit & joisinoBit
    r = 0
    c = common
    while(c != 0):
        if c%2 == 1:
            r += 1
        c //= 2
    return P[shopIdx][r]


ma = -10**10
for bit in range(1,2 ** 10):
    r = 0
    for shopIdx in range(N):
        r += rieki(shopIdx, bit)
    ma = max(ma, r)

print(ma)

Submission status: Accepted

Solution code:
N = int(input())
F = []
P = []
for i in range(N):
    temp = [int(i) for i in input().split()]
    tt = 0b0
    for j in range(len(temp)):
        tt += 2 ** j * temp[j]
    F.append(tt)
    
for i in range(N):
    temp = [int(i) for i in input().split()]
    P.append(temp)

def bene(bit):
    res = 0
    for i in range(N):
        a = bit & F[i]
        cc = 0
        for j in str(bin(a)):
            if j == "1":
                cc += 1
        res += P[i][cc]
    return res

benes = [bene(i) for i in range(1,1024)]
benes.sort()
print(benes[-1])

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]
import numpy as np
N = int(input())
F = np.zeros((N, 10), dtype = int)
P = np.zeros((N, 11), dtype = int)
ans = -10**11
for i in range(N):
    F[i] = np.array(inpl())
for i in range(N):
    P[i] = np.array(inpl())
for ctr in range(1,1024):
    tmpans = 0
    ctr = list(map(int, bin(ctr)[2:]))
    ctr = np.array([0]*(10-len(ctr)) + ctr)
    for j in range(N):
        tmpans += P[j][np.dot(ctr,F[j])]
    ans = max(ans, tmpans)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
f = []
for _ in range(n):
    f.append(input().split())
p = []
for _ in range(n):
    p.append(list(map(int, input().split())))

res = None
for i in range(1,2**10):
    joisino = [str(i>>n&1) for n in range(10)]
    prof = 0
    for j in range(n):
        c = 0
        for k in range(10):
            if joisino[k]=="1" and f[j][k]=="1":
                c += 1
        prof += p[j][c]
    if res is None:
        res = prof
    else:
        res = max(res, prof)
print(res)

Submission status: Accepted

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

cnt=[0]*n
ans=tmp=0
for i in range(1,1<<10):
    tmp=0
    cnt=[0]*n
    for j in range(10):
        if (i&(1<<j)):
            for k in range(n):
                if (f[k][j]): cnt[k]+=1
    for l in range(n):
       tmp+=p[l][cnt[l]]
    if i==1: ans=tmp
    else: ans=max(ans,tmp)

print(ans)

Submission status: Accepted

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

ans = - 10 ** 10
for i in range(1, 2 ** 10):
    ans = max(ans, sum([P[j][bin(i&F[j]).count('1')] for j in range(N)]))
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)]

res = -float('inf')
for i in range(1,1<<10):
    a = [0]*n
    for j in range(10):
        for m in range(n):
            if i&1 and f[m][j]:
                a[m] += 1
        i >>= 1
    w = 0
    for j in range(n):
        w += p[j][a[j]]
    res = max(res,w)
print(res)

Submission status: Accepted

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

ans = -10**18
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 = [[0 for j in range(10)] for i in range(n)]
p = [[0 for i in range(11)] for j in range(n)]
for i in range(n):
    f[i] = [int(i) for i in input().split()]
for i in range(n):
    p[i] = [int(i) for i in input().split()]

totalProfit = 0
N = [i for i in range(10)]  # N = bit探索する桁数
for i in range(1, 1 << len(N)):
    output = []
    for j in range(len(N)):
        if ((i >> j) & 1) == 1:
            output.append(j)  # このjが今回探索するindexの1つ
    profit = 0
    for j in range(n):
        sameOpen = 0
        for k in output:
            if f[j][k] == 1:  # 店j,曜日時間帯kと営業日被り
                sameOpen += 1
        profit += p[j][sameOpen]
        # print("store:{} sameOpen:{}".format(j, sameOpen))
    # print("profit:{} {}".format(profit, output))
    if i == 1:
        totalProfit = profit
    else:
        totalProfit = max(totalProfit, profit)
print(totalProfit)

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

maxp = -100000000000
def culc(nowt, open):
    global n
    global f
    global p
    global maxp
    if 10 <= nowt:
        tmp_max = 0
        for i in range(n):
            count = 0
            for j in range(10):
                if f[i][j] == 1 and open[j] == 1:
                    count += 1
            tmp_max += p[i][count]
        maxp = max(maxp, tmp_max)
    else:
        culc(nowt + 1, open + [0])
        culc(nowt + 1, open + [1])
for i in range(1, 11):
    culc(i, [0] * (i - 1) + [1])
print(maxp)

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)]
combos = sorted(list(itertools.product([0, 1], repeat=10)))
ans = -float('inf')

for combo in combos[1:]:
  total = 0

  for i in range(len(F)):
    count = 0      
    for a, b in zip(combo, F[i]):
      if a == 1 and b == 1:
        count += 1
    total += P[i][count]
  
  ans = max(ans, total)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
isopen = [list(map(int,input().split())) for i in range(N)]
gain = [list(map(int,input().split())) for i in range(N)]
 
ans = -float('inf')
for i in range(1,2**10):
    tmp = 0
    for n in range(N):
        c = 0
        for b in range(10):
            if (i >> b) & isopen[n][b]:
                c += 1
        tmp += gain[n][c]
    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)]
result = -(10 ** 7) * 100

for i in range(1, 1024):
    array = []
    num = i
    for _ in range(10):
        array.append(num%2)
        num //= 2

    point = 0
    for j in range(N):
        counter = 0
        for k in range(10):
            if array[k] == 1 and F[j][k] == 1:
                counter += 1

        point += P[j][counter]

    result = max(result, point)

print(result)

Submission status: Accepted

Solution code:
N=int(input())
Time_Table=[[int(i) for i in input().split()] for i in range(N)]
Price=[[int(i) for i in input().split()] for i in range(N)]
S=-10000000000000
for i in range(1,1024):
  List_kari=[]
  List=[0]*10
  List_kari=list(str(bin(i))) 
  S_kari=0
  del List_kari[0:2]
  for j in range(len(List_kari)):
    List[9-j]=int(List_kari[len(List_kari)-j-1])
  for k in range(N):
    m=0
    for n in range(10):
      if Time_Table[k][n]==1 and List[n]==1:
        m+=1
    S_kari+=Price[k][m]    
  if S<S_kari:
    S=S_kari
print(S)

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())))
    
    
def calc_profit(open_list):
    if not (True in open_list):
        return -10**27
    count = [0 for i in range(N)]
    for i in range(10):
        if open_list[i]:
            for j in range(N):
                if F[j][i]==1:
                    count[j]+=1
    profit=0
    for i in range(N):
        profit+=P[i][count[i]]
    return profit

def get_max(l):
    if len(l)==10:
        return calc_profit(l)
    else:
        return max(get_max(l+[True]),get_max(l+[False]))

print(get_max([]))

Submission status: Accepted

Solution code:
n = int(input())
f = []
for i in range(n):#h:高さ
    f.append([int(m) for m in input().split()])
p = []
for i in range(n):#h:高さ
    p.append([int(m) for m in input().split()])

fcount = 0
pcount= 0
pli = []
for i0 in range(2):
    for i1 in range(2):
        for i2 in range(2):
            for i3 in range(2):
                for i4 in range(2):
                    for i5 in range(2):
                        for i6 in range(2):
                            for i7 in range(2):
                                for i8 in range(2):
                                    for i9 in range(2):
                                        ili = [i0,i1,i2,i3,i4,i5,i6,i7,i8,i9]
                                        if ili != [0,0,0,0,0,0,0,0,0,0]:
                                            for j in range(n):
                                                for k in range(10):
                                                    if ili[k] == f[j][k] and ili[k] == 1:
                                                        fcount += 1
                                                pcount += p[j][fcount]
                                                fcount = 0
                                            pli.append(pcount)
                                            pcount = 0
print(max(pli))

Submission status: Accepted

Solution code:
n = int(input())
f = []
for _ in [0]*n:
  f += [list(map(int,input().split()))]
p = []
for _ in [0]*n:
  p += [list(map(int,input().split()))]
m = -10000001*n
for x in range(1,1024):
  k = 0
  s = format(x,'010b')
  for t in range(n):
    k += p[t][sum([int(s[i])*f[t][i] for i in range(10)])]
  m = max(m,k)
print(m)

Submission status: Accepted

Solution code:
# encoding: utf-8
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 bc10(num):
    num_tmp = num
    ret = 0
    for i in range(10):
        if num_tmp % 2: ret += 1
        num_tmp = num_tmp >> 1
    return ret

# re-arrange enemy infomation
F_mask = [0] * N
for i, F_row in enumerate(F): F_mask[i] += sum([(2 ** j) * item for j, item in enumerate(F_row)])

ans = - (10 ** 7) * N
for case in range(1, 2 ** 10):
    # decide joisino-onechan's status
    joisino = 0
    case_tmp = case
    for i in range(10):
        joisino += (case_tmp % 2) << i
        case_tmp = case_tmp >> 1
    # calc profit
    profit = 0
    for i, enemy in enumerate(F_mask): profit += P[i][bc10(joisino & enemy)]
    # update
    # print("#", joisino, profit)
    if ans < profit: ans = profit

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
F=[]
P=[]
k=[0]*10
for i in range(N):
    F.append(list(map(int, input().strip().split())))
for i in range(N):
    P.append(list(map(int, input().strip().split())))


ans=-10**10
for i in range(1,2**11-1):
    tmp=0
    s='{0:010b}'.format(i)
    for k in range(N):
        c=0
        for j in range(10):
            if (int(s[j])+F[k][j])==2:
                c+=1
        tmp+=P[k][c]
    ans=max(ans,tmp)
    
print(ans)

Submission status: Accepted

Solution code:
import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    #aF = [0]*iN
    #aP = [0]*iN
    #for i in range(iN):
    #   aF[i] = int(input().rstrip().replace(' ',''),2)
    aF = list(map(lambda x:int(input().rstrip().replace(' ',''),2),range(iN)))
    #for i in range(iN):
    #   aP[i] = [int(_) for  _ in input().split()]
    aP = list(map(lambda x:[int(_) for _ in input().split()],range(iN)))
    iD = 2**10
    #iMax = -1*(10**10)
    #for i in range(1,iD):
        #iM = 0
    #   iM = sum(map(lambda x:aP[x][bin(aF[x] & i).count("1")],range(iN)))
        #for j in range(iN):
        #   iM += aP[j][bin(aF[j] & i).count("1")]
    #   if iMax < iM:
    #       iMax = iM
    #こんなふうにも書けるのか。うーむ呪文っぽいわりにそんなに速くならなそう。
    print(max(sum( map(lambda x:aP[x][bin(aF[x] & i).count("1")],range(iN)))for i in range(1,iD)))
    #print(iMax)
解()

Submission status: Accepted

Solution code:
import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aF = [0]*iN
    aP = [0]*iN
    #for i in range(iN):
    #   aF[i] = int(input().rstrip().replace(' ',''),2)
    aF = list(map(lambda x:int(input().rstrip().replace(' ',''),2),range(iN)))
    #for i in range(iN):
    #   aP[i] = [int(_) for  _ in input().split()]
    aP = list(map(lambda x:[int(_) for _ in input().split()],range(iN)))
    iD = 2**10
    iMax = -1*(10**10)
    for i in range(1,iD):
        #iM = 0
        iM = sum(map(lambda x:aP[x][bin(aF[x] & i).count("1")],range(iN)))
        #for j in range(iN):
        #   iM += aP[j][bin(aF[j] & i).count("1")]
        if iMax < iM:
            iMax = iM
    print(iMax)
解()

Submission status: Accepted

Solution code:
import sys
def 解():
    input = sys.stdin.readline
    iN = int(input())
    aF = [0]*iN
    aP = [0]*iN
    for i in range(iN):
        aF[i] = int(input().rstrip().replace(' ',''),2)
    for i in range(iN):
        aP[i] = [int(_) for  _ in input().split()]
    iD = 2**10
    iMax = -1*(10**10)
    for i in range(1,iD):
        iM = 0
        for j in range(iN):
            iM += aP[j][bin(aF[j] & i).count("1")]
        if iMax < iM:
            iMax = iM
    print(iMax)
解()

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)]
total = -10**10
for i in range(1, 1024):
    x = list(map(int, list(format(i, '010b'))))
    tmp = 0
    for j in range(n):
        a = 0
        for k in range(10):
            a += x[k] * f[j][k]
        tmp += p[j][a]
    total = max(tmp, total)
print(total)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Nov  4 17:22:42 2018
ABC080
@author: maezawa
"""
import itertools as itr

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())))
    
#print(f)
#print(p)
profit = -10**10
for oph in itr.product([0,1], repeat=10):
    if oph == (0,0,0,0,0,0,0,0,0,0):
        continue
    c = [0]*n
    for i in range(n):
        c[i] = sum([f[i][j]*oph[j] for j in range(10)])
    pcurrent = sum([p[i][c[i]] for i in range(n)])
    if pcurrent > profit:
        profit = pcurrent
        #print(oph)

print(profit)

Submission status: Accepted

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

Ans = -float("inf")
for i in range(1, 2**10):
    A = list(format(i, "b").zfill(10))
    Index = []
    for j in range(10):
        if A[j] == "1":
            Index.append(j)
    Benefit = 0
    for j in range(N):
        count = 0
        for a in Index:
            if F[j][a] == 1:
                count += 1
        Benefit += P[j][count]
    Ans = max(Ans, Benefit)
print(Ans)