题目:1782. The jackpot
思路:最大字段和
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> using namespace std; #define maxn 10010 int dp[maxn],num[maxn]; int main() { int n; while(scanf("%d",&n),n) { int mx=0; memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { scanf("%d",&num[i]); if(num[i]>0) dp[i]=num[i]+dp[i-1]; else { dp[i]=max(dp[i],dp[i-1]+num[i]); } mx=max(mx,dp[i]); } if(mx>0) printf("The maximum winning streak is %d. ",mx); else printf("Losing streak. "); } }