想法:
用DP做,設MSS為累加到目前的値,如果MSS是負的,那麼MSS=num,否則MSS+=num。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
using namespace std; | |
int main() | |
{ | |
int N, num; | |
while (scanf("%d", &N) && N) { | |
int Max = 0; | |
int MSS = -1; | |
while (N--) { | |
scanf("%d", &num); | |
if (MSS < 0) MSS = num; | |
else MSS += num; | |
if (MSS > Max) Max = MSS; | |
} | |
if (Max > 0) printf("The maximum winning streak is %d.\n", Max); | |
else puts("Losing streak."); | |
} | |
} |
沒有留言:
張貼留言