Cod sursa(job #2224176)

Utilizator andrei.arnautuAndi Arnautu andrei.arnautu Data 23 iulie 2018 12:53:52
Problema Bile2 Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
/**
  *  Worg
  */
#include <cstdio>
#include <algorithm>

FILE *fin = freopen("bile2.in", "r", stdin); FILE *fout = freopen("bile2.out", "w", stdout);

const int MAX_N = 50 + 1;
const long long INF = 1e16;

long long n, d, a, b;
long long comb[MAX_N][MAX_N];
long long dp[MAX_N][MAX_N];

void ComputeComb() {
  long long max_comb = 0;

  comb[0][0] = 1;
  for(int i = 1; i < MAX_N; i++) {
    comb[i][0] = 1;
    for(int j = 1; j <= i; j++) {
      comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
    }
  }
}

void ComputeDp() {
  for(int j = 1; j <= n; j++) {
    dp[1][j] = j;
  }

  for(int i = 2; i <= n; i++) {
    for(int j = i; j <= n; j++) {
      dp[i][j] = dp[i][j - 1];

      for(int k = j - d - 1; k > 0; k--) {
        dp[i][j] += dp[i - 1][k];
      }
    }
  }

  const double min_prob = (double) a / (double) b;

  int answer = n;
  for(int i = n - 1; i > 0; i--) {
    double prob_here = 1.0 - ((double)dp[i][n] / (double)comb[n][i]);

    if(prob_here >= min_prob) {
      answer = i;
    } else {
      break;
    }
  }

  printf("%d\n", answer);
}

int main() {
  scanf("%lld%lld%lld%lld", &n, &d, &a, &b);

  ComputeComb();

  ComputeDp();

  return 0;
}