Cod sursa(job #3307276)

Utilizator informatica1218alexia petre informatica1218 Data 19 august 2025 15:44:11
Problema Ubuntzei Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include "bits/stdc++.h"
using namespace std;
ifstream f ("recyclebin.in");
ofstream g ("recyclebin.out");
long long v[1002],p2[12],s[1002][1002];
int main ()
{
    long long n,x,stop,max1,y,nr,stare,b,a;
    f>>n;
    for (x=1;x<=n;x++)
    {
        f>>v[x];
    }
    p2[0]=1;nr=0;
    for (x=1;p2[x-1]<=n;x++)
    {
        p2[x]=p2[x-1]*2;
        nr++;
    }
    nr++;
    for (x=1;x<=n;x++)
    {
        for (stare=0;stare<=x;stare++)
        {
            s[x][stare]=s[x-1][stare]+v[x];
            for (b=0;b<nr;b++)
            {
                a=1<<b;
                if (stare&a)
                {
                if (x-a>=0) s[x][stare]=max(s[x][stare],s[x-a][stare-a]);
                }
            }
        }
    }
    max1=0;
    for (x=1;x<=n;x++)
    {for (stare=0;stare<=n;stare++)
    {
        max1=max(s[x][stare],max1);
    }}
    g<<max1;
    f.close ();
    g.close ();
    return 0;
}