题目:1782. The jackpot
思路:最大字段和
#include#include #include #include #include using namespace std;#define maxn 10010int 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.\n",mx); else printf("Losing streak.\n"); }}