Cod sursa(job #2362660)

Utilizator Andrei_RAndrei Roceanu Andrei_R Data 3 martie 2019 11:29:09
Problema Zebughil Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
#include<stdio.h>
#include<string.h>
#define Nm 17
#define max(a,b) ((a)>(b)?(a):(b))
int A[1<<Nm],B[1<<Nm],G[Nm],n,g;

void read()
{
    int i;

    scanf("%d%d",&n,&g);
    for(i=0;i<n;++i)
        scanf("%d",G+i);
}

void solve()
{
    int i,j;

    memset(B,0,sizeof(B));
    A[0]=0; B[0]=-1;
    for(i=1;i<1<<n;++i)
        for(j=0;j<n;++j)
            if(i&1<<j)
                if(B[i^1<<j]<G[j])
                {
                    A[i]=A[i^1<<j]+1;
                    B[i]=max(B[i],g-G[j]);
                }
                else
                {
                    A[i]=A[i^1<<j];
                    B[i]=max(B[i],B[i^1<<j]-G[j]);
                }
}

int main()
{
    int t=3;

    freopen("zebughil.in","r",stdin);
    freopen("zebughil.out","w",stdout);

    while(t--)
    {
        read();
        solve();
        printf("%d\n",A[(1<<n)-1]);
    }
    return 0;
}