度小满笔试 凉凉
度小满算法笔试第二题,过了交卷时间两分钟,才把代码敲完,根本没来得及copy到考试端,也不知道这个方法能ac多少(其实就是刷题时候的火车站问题)
n,w=4,2 wn = [1, 1, 1, 1] tn = [2,1,2,2] dp = [0]*(sum(tn)+1) j = 0 for i in range(len(dp)): he = sum(dp[:i+1]) while j<len(wn) and (w-he)>=wn[j]: dp[i]+=wn[j] dp[i+tn[j]]-=wn[j] j+=1 he = sum(dp[:i+1]) print(dp) for i in range(len(dp)-1,0,-1): if dp[i] ==0: continue else: print(i) break