Cod sursă (job #378259)

Utilizator avatar vladth11 Vlad Haivas vladth11 IP ascuns
Problemă Bart (clasele 9-10) Compilator cpp | 0,70 kb
Rundă Arhiva de probleme Status evaluat
Dată 25 apr. 2018 08:30:43 Scor 0
#include<fstream>
#include<algorithm>
using namespace std;

ifstream cin("balance.in");
ofstream cout("balance.out");

int v[10], n, rez = 0, stanga, dreapta;

void asezareinit(int x)
{
    if(x == n)
    {
        rez++;
        return;
    }
    if (stanga + v[x] <= dreapta)
    {
        stanga += v[x];
        asezareinit(x + 1);
        stanga -= v[x];
    }
    dreapta += v[x];
    asezareinit(x + 1);
    dreapta -= v[x];
}

int main()
{
    cin >> n;
    for(int i=0; i<n; i++)
      cin >> v[i];
    sort(v, v+n);
    do
    {
        stanga=0; dreapta=0;
        asezareinit(0);

    }while(next_permutation(v,v+n));
    cout << rez <<"\n";
    return 0;
}