一个工厂制造的产品形状都是长方体,它们的高度都是h,长和宽都相等,一共有六个型号,他们的长宽分别为1×1、2×2、3×3、4×4、5×5、6×6。这些产品通常使用一个 6×6×h 的长方体包裹包装然后邮寄给客户。因为邮费很贵,所以工厂要想方设法的减小每个订单运送时的包裹数量。他们很需要有一个好的程序帮他们解决这个问题从而节省费用。现在这个程序由你来设计。
while True:
try:
box = list(map(int,input().split()))
ini_count = sum(box[3:])+(box[2]+3)//4
box[2] = box[2]%4
remain1 = box[0]
remain2 = box[1]
remain_space = 0 # 假设某个位置没有装满2,留给1的
# 针对为5*5的箱子,存放1*1后的结果
if box[4]>0:
remain1 = max(0,remain1-box[4]*11)
# 针对4*4的箱子,先存放2*2,再存放1*1
if box[3]>0:
if box[3]>remain2*5:
remain_space += (box[3]*20-remain2*4)
remain2 = 0
remain1 = max(0,remain1-remain_space)
else:
remain2 = max(0,remain2-box[3]*5)
# 针对3*3的箱子,先放2*2,再放1*1
if box[2]==1:
if remain2 > 5:
remain2 -= 5
remain1 = max(0,remain1-7)
else:
remain_space += (27 - remain2*4)
remain2 = 0
remain1 = max(0,remain1-remain_space)
if box[2]==2:
if remain2 > 4:
remain2 -= 4
reamin1 = max(0,remain1-4)
else:
remain_space += (18-remain2*4)
remin2 = 0
remain1 = max(0,remain1-remain_space)
if box[2]==3:
if remain2>2:
remain2 -= 2
remain1 = max(0,remain1-2)
else:
remain_space += (9-remain2*4)
remain2 = 0
remain1 = max(0,remain1-remain_space)
count = ini_count+(remain1+remain2*4+35)//36
print(count)
except:
break
A[n,m]是一个n行m列的矩阵,a[i,j]表示A的第i行j列的元素,定义x[i,j]为A的第i行和第j列除了a[i,j]之外所有元素(共n+m-2个)的乘积,即x[i,j]=a[i,1]a[i,2]...a[i,j-1]...a[i,m]a[1,j]a[2,j]...a[i-1,j]a[i+1,j]...a[n,j],现输入非负整形的矩阵A[n,m],求MAX(x[i,j]),即所有的x[i,j]中的最大值。
def compute(A,index):
dp1 = [1]*len(A)
dp2 = [1]*len(A)
for i in range(1,len(A)):
dp1[i] = dp1[i-1]*A[i-1]
for j in range(len(A)-2,-1,-1):
dp2[j] = dp2[j+1]*A[j+1]
return dp1[index]*dp2[index]
def get_col(A,j):
m,n = len(A),len(A[0])
col = []
for i in range(m):
col.append(A[i][j])
return col
while True:
try:
n,m = list(map(int,input().split()))
res = []
for i in range(n):
res.append(list(map(int,input().split())))
result = float("-inf")
for i in range(n):
for j in range(m):
row = res[i]
col = get_col(res, j)
result = max(result,compute(row,j)*compute(col,i))
print(result)
except:
break