【題解】ZeroJudge a540: 10684 – The jackpot

【範例】DP: Max 1D Range Sum
題目敘述:https://zerojudge.tw/ShowProblem?problemid=a540
Virtual Judge: https://vjudge.net/problem/UVA-10684

while True:
    try:
        n = int(input())
        lst = list(map(int, input().split()))
        total = 0
        maxi = lst[0]
        for num in lst:
            total += num
            if total > maxi:
                maxi = total
            if total < 0:
                total = 0
        if maxi <= 0:
            print('Losing streak.')
        else:
            print('The maximum winning streak is ', maxi, '.', sep = '')
    except:
        break
分享本文 Share with friends