QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#98954#5105. Hand of the Free MarkeduphargaurCompile Error//C++201.4kb2023-04-21 02:03:532023-04-21 02:03:56

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-21 02:03:56]
  • 评测
  • [2023-04-21 02:03:53]
  • 提交

answer

#include <iostream>
using namespace std;

int k, m, n, a[99], b[99];
long double ans, totnum, num, p;

long double nCr(int x, int y) {
    long double res = 1;
    for (int i = 1; i <= y; ++i)
        res /= i;
    for (int i = 1; i <= y; ++i)
        res *= (x - i + 1);
    return res;
}
// long double fact(long double n);
 
// long double nCr(long double n, long double r)
// {
//     return fact(n) / (fact(r) * fact(n - r));
// }
 
// // Returns factorial of n
// long double fact(long double n)
// {
//       if(n==0)
//       return 1;
//     long double res = 1;
//     for (long double i = 2; i <= n; i++)
//         res = res * i;
//     return res;
// }
void dfs(int nw, int sm) {
    if (nw > m) {
        if (sm ^ k)
            return;
        num = 1;
        p = 0;
        for (int i = 1; i <= m; ++i)
            num *= C(a[i], b[i]), p += (long double)b[i] / (a[i] - b[i] + 1);
        for (int i = 1; i < k; ++i)
            p *= i;
        if (p > 1)
            ans += num / totnum;
        else
            ans += num / totnum * p;
        return;
    }
    for (int i = 0; i + sm <= k && i <= a[nw]; ++i)
        b[nw] = i, dfs(nw + 1, sm + i);
}

int main() {
    cin >> k >> m;
    for (int i = 1; i <= m; ++i)
        cin >> a[i], n += a[i];
    totnum = nCr(n, k);
    dfs(1, 0);
    cout.precision(10);
    cout << fixed << ans << endl;
    return 0;
}

詳細信息

answer.code: In function ‘void dfs(int, int)’:
answer.code:39:20: error: ‘C’ was not declared in this scope
   39 |             num *= C(a[i], b[i]), p += (long double)b[i] / (a[i] - b[i] + 1);
      |                    ^