Cod sursa(job #1347470)

Utilizator StefanMudragMudrag Stefan StefanMudrag Data 18 februarie 2015 23:14:13
Problema Oo Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>
#define NMAX 100002
using namespace std;
ifstream fin("oo.in");
ofstream fout("oo.out");
int a[NMAX],uz[NMAX];
int n;
vector<int>s(NMAX,-1);
void read()
{
    fin>>n;
    for(int i=1;i<=n;i++)
        fin>>a[i];
    fin.close();

}
int solve(int i)
{
    int x1,x2,x3;

    if(s[i]!=-1)
    {if(!uz[i])uz[i]=1; return s[i];}
    x1=solve(i-1);
    x2=solve(i-3)+a[i]+a[i-1];
    if(i==n)
   {

        if(uz[i-3])x2=x2-a[i]-a[i-1];
        x3=a[1]+a[n];

   }
    s[i]=max(x1,x2);
    return s[i];
}
int main()
{
    read();
    s[0]=0;s[1]=a[n]+a[1];
    s[-1]=0;
   uz[2]=1;
   fout<<solve(n-1);

    fout.close();
    return 0;
}