Cod sursa(job #3229020)

Utilizator ChopinFLazar Alexandru ChopinF Data 12 mai 2024 23:13:51
Problema Oite Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <bits/stdc++.h>

using namespace std;

std::ifstream fin("oite.in");
std::ofstream fout("oite.out");

bool has_4_bits(int x)
{
    int k = 0;
    while(x > 0)
    {
        k += (x & 1);
        x >>= 1;
    }
    return (k == 4);
}
vector<int>v;
int main()
{
    int c , l;
    fin >> c >> l;
    for(int i = 0 ; i < c ; ++i)
    {
        int x;
        fin >> x;
        v.push_back(x);
    }
    int ans = 0;
    for(int i = 0 ; i < (1 << c) ; ++i)
    {
        if(has_4_bits(i))
        {
            //fout << i << "\n";
            int s = 0;
            for(int j = 0 ; j < c ; ++j)
            {
                if(i & ( 1 << j))
                {
                    s += v[j];
                }
            }
            if(s == l)++ans;
        }
    }
    fout << ans;
}