Cod sursa(job #420964)

Utilizator devilkindSavin Tiberiu devilkind Data 20 martie 2010 20:44:30
Problema Prod Scor Ascuns
Compilator cpp Status done
Runda Marime 0.99 kb
#include <stdio.h>
#include <algorithm>

using namespace std;

#define NMAX 1000

long long V[NMAX];
long long H[NMAX];
long long N;
long long st[NMAX];
long long sol = 0, sx, sy;

void back(int nivel) {
  if (nivel == N + 1) {
    long long x = 0, y = 0, i;
    for (i = 1; i <= N / 2; i++) {
      x = x * 10 + st[i];
    }

    for (i = N / 2 + 1; i <= N; i++) {
      y = y * 10 + st[i];
    }

    if (x * y > sol) {
      sol = x * y;
      sx = x;
      sy = y;
    }

    return;
  }

  int i;
  for (i = 1; i <= N; i++) {
    if (!H[i]) {
      st[nivel] = V[i];
      H[i] = 1;
      back(nivel + 1);
      H[i] = 0;
    }
  }
}

int main() {
  freopen("prod.in", "r", stdin);
  freopen("prod.out", "w", stdout);

  long long i, j, x;
  for (i = 0; i < 10; i++) {
    scanf("%lld ", &x);
    for (j = 1; j <= x; j++) {
      V[++N] = i;
    }
  }

  sort(V + 1, V + N + 1);
/*  for (i = 1; i <= N; i++) {
    printf("%lld ", V[i]);
  }
  printf("\n");*/

  back(1);
  printf("%lld ", sol);
  return 0;
}