n
,x[0]
,x[1]
,x[2]
使用n = a*x[0] + b*x[1] + c*x[2]
和n<=4000
找maxi = a+b+c (a,b,c>=0)
当我使用n=3164
,x = [42, 430, 1309]
时。答案必须是15.但为什么round(15.0)==15.0
是假的?我在第17行尝试打印i, j, tf, ti, maxi
时找到了它:
x = [0, 0, 0]
n, x[0], x[1], x[2] = map(float, raw_input().split())
x.sort(reverse=True) #suppose x[0]>=x[1]>=x[2]
maxi=0
if x[2] == 1.0:
print int(n)
else:
for i in range(int(n/x[0])+1): #first loop to find a: a <= n/x[0]
for j in range(int(n/x[1])+1): #second loop to find b: b <= n/x[1]
#used math to find equation I found:
tf = float(i*(1.0-x[0]/x[2]) + j*(1.0-x[1]/x[2]) + n/x[2])
ti = int(round(tf))
if tf > n or tf <0:
break
if ti==tf and ti >= maxi: #find satisfactory value
maxi = ti
#print i, j, ti, tf, maxi
print maxi