Cod sursa(job #732063)

Utilizator robertpoeRobert Poenaru robertpoe Data 9 aprilie 2012 17:06:32
Problema Zebughil Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<fstream>
#define special_dim (1<<17)
#define bitn (1<<n)
#define bitk (1<<k)
using namespace std;
ifstream f("zebughil.in");
ofstream g("zebughil.out");
int a[special_dim];
int arb[17];
int n,m,k,i,j,nr=3;
int main()
{
    for(nr=3;nr;--nr)
    {
        f>>n>>m;
        for(i=0;i<n;++i)
			f>>arb[i];
        for(i=0;i<bitn;++i)
			a[i]=-1;
        a[0]=m;
        for(i=1;i<=n;++i)
        {
            for(j=0;j<bitk;++j)
            {
                if(a[j]!=-1)
                a[j]=m;
                for(k=0;k<n;++k)
                    if(j&&bitk&&a[j-bitk]-arb[k]>a[j])
                            a[j]=a[j-bitk]-arb[k];
            }
            if(a[bitn-1]>=0)
            break;
        }
        g<<i<<"\n";
    }
    return 0;
}