标签:
Description
Owen had been through unrequited love with N MM for a long time. In order to celebrate the 8th anniversary of ZOJ, he decided to "watch white".
One night, MMs are sitting in a ring. Owen‘s plan is to give them love letters secretly so that MMs who receive letters will know that Owen loves them. Besides, each MM has a "happy point". The greater it is, the happier Owen will be if that MM receives his love letter.
One more problem. MM is very sensitive, so she will know if Owen (even secretly) drops a letter to the girl next to her. Meanwhile, MM is likely to be jealous. If she receives the love letter and finds that some other girl also gets a love letter, she will pia Owen to death.
Owen, as a smart boy, won‘t let MM pia him, and decides to program to calculate the maximum sum of happy points he can get. However, love is blind. Poor Owen has lost the ability to program. So he turns to you.
Input
There are no more than 10 test cases.
Output
One line for each test case.
Sample Input
5 1 2 3 4 5 6 1 2 3 4 5 6
Sample Output
8 12
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<cmath> #include<algorithm> #include<cstdlib> #include<queue> #include<vector> #include<stack> #include<set> using namespace std; int dp1[1000005]; int dp2[1000005]; int a[1000005]; int n; int main() { while(scanf("%d",&n)!=EOF) { int ans; for(int i=1;i<=n;i++) { dp1[i]=0; dp2[i]=0; } for(int i=1;i<=n;i++) scanf("%d",&a[i]); dp1[1]=a[1]; for(int i=2;i<=n-1;i++) { dp1[i]=dp1[i-2]+a[i]; if(dp1[i]<dp1[i-1]) dp1[i]=dp1[i-1]; } for(int i=2;i<=n;i++) { dp2[i]=dp2[i-2]+a[i]; if(dp2[i]<dp2[i-1]) dp2[i]=dp2[i-1]; } ans=max(dp1[n-1],dp2[n]); printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4433593.html