Cod sursa(job #1856173)

Utilizator roxannemafteiuMafteiu-Scai Roxana roxannemafteiu Data 24 ianuarie 2017 16:56:49
Problema Zebughil Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <fstream>
#include <utility>

#define x first
#define y second

using namespace std;

const int NMAX = 17;

ifstream f("zebughil.in");
ofstream g("zebughil.out");

int N, G;
int g[NMAX + 3];

pair<int, int> d[(1 << NMAX) + 4];

void solve() {
    f >> N >> G;
    for (int i = 0; i < N; ++i)
        f >> g[i];

    for (int j = 1; j < (1 << N); ++j) {
        d[j] = {NMAX, 0};
        for (int i = 0; i < N; ++i)
            if (j >> i & 1) {
                int p = j ^ 1 << i;
                if (d[p].y + g[i] <= 0) {
                    d[j] = min(d[j], {d[p].x, d[p].y + g[i]});
                } else {
                    d[conf] = min(d[j], {d[p].x + 1, -G + g[i]});
                }
            }
    }

    g << d[(1 << N) - 1].x << '\n';
}

int main() {
    int T = 3;
    while (T--) {
        solve();
    }

    return 0;
}