結果

問題 No.1688 Veterinarian
ユーザー tnakao0123tnakao0123
提出日時 2021-09-25 02:40:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 3,000 ms
コード長 1,630 bytes
コンパイル時間 748 ms
コンパイル使用メモリ 93,732 KB
実行使用メモリ 17,716 KB
最終ジャッジ日時 2023-09-18 22:46:54
合計ジャッジ時間 1,611 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 3 ms
5,052 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 28 ms
17,716 KB
testcase_09 AC 27 ms
17,660 KB
testcase_10 AC 7 ms
6,936 KB
testcase_11 AC 4 ms
5,516 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 4 ms
5,092 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 7 ms
7,552 KB
testcase_16 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1688.cc:  No.1688 Veterinarian - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;
const int MAX_A = 50;
const int MAX_B = 50;
const int MAX_C = 50;

/* typedef */

/* global variables */

double dp[MAX_N + 1][MAX_A + 1][MAX_B + 1][MAX_C + 1];

/* subroutines */

inline int nc2(int n) { return n * (n - 1) / 2; }

/* main */

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

  dp[0][a][b][c] = 1.0;

  for (int i = 0; i < n; i++)
    for (int x = a; x > 0; x--) {
      int a2 = nc2(x);
      for (int y = b; y > 0; y--) {
	int b2 = nc2(y);
	for (int z = c; z > 0; z--)
	  if (dp[i][x][y][z] > 0.0) {
	    int s2 = nc2(x + y + z), c2 = nc2(z);

	    dp[i + 1][x - 1][y][z] += dp[i][x][y][z] * a2 / s2;
	    dp[i + 1][x][y - 1][z] += dp[i][x][y][z] * b2 / s2;
	    dp[i + 1][x][y][z - 1] += dp[i][x][y][z] * c2 / s2;
	    dp[i + 1][x][y][z] += dp[i][x][y][z] * (s2 - (a2 + b2 + c2)) / s2;
	  }
      }
    }

  double ea = 0.0, eb = 0.0, ec = 0.0;
  for (int x = a; x > 0; x--)
    for (int y = b; y > 0; y--)
      for (int z = c; z > 0; z--)
	if (dp[n][x][y][z] > 0.0) {
	  ea += dp[n][x][y][z] * (a - x);
	  eb += dp[n][x][y][z] * (b - y);
	  ec += dp[n][x][y][z] * (c - z);
	}

  printf("%.16lf %.16lf %.16lf\n", ea, eb, ec);
  return 0;
}
0