#39516: 簡單的方式 python


lcy920126@gmail.com (LCY)

學校 : 國立臺北大學
編號 : 219523
來源 : [120.126.126.13]
最後登入時間 :
2024-02-24 11:27:44
f606. 2. 流量 -- 2021年1月APCS | From: [120.126.126.13] | 發表日期 : 2024-03-02 13:54

import copy

n, m, k = map(int, input().split())
list_Q = [list(map(int, input().split())) for _ in range(n)]
list_C = [list(map(int, input().split())) for _ in range(k)]
ans = []
for c in range(k):  # 每次看一个方案
    money = 0
    temp_q = copy.deepcopy(list_Q)
    temp_c = copy.deepcopy(list_C[c])

    i = 0
    while i < len(temp_c):  # 不能使用for迴圈 必須改用while代替
        j = i + 1
        while j < len(temp_c):
            if temp_c[i] == temp_c[j]:
                for m in range(len(temp_q[i])):
                    temp_q[i][m] += temp_q[j][m]  # 相同的地區流量合併
                temp_q.pop(j)
                temp_c.pop(j)
            else:
                j += 1
        i += 1

    for i in range(len(temp_q)):
        for j in range(len(temp_q[i])):
            if temp_c[i] == j:
                money += temp_q[i][j]
            elif temp_q[i][j] > 1000:
                money += (temp_q[i][j] - 1000) * 2 + 3000
            else:
                money += temp_q[i][j] * 3
    ans.append(money)

print(min(ans))
 
ZeroJudge Forum