結果

問題 No.2389 Cheating Code Golf
ユーザー tnakao0123tnakao0123
提出日時 2023-07-25 15:34:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,145 bytes
コンパイル時間 417 ms
コンパイル使用メモリ 45,404 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 07:35:24
合計ジャッジ時間 2,132 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 11 ms
6,940 KB
testcase_04 AC 11 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 6 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 4 ms
6,944 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 5 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 5 ms
6,948 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 4 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 2 ms
6,940 KB
testcase_34 AC 5 ms
6,944 KB
testcase_35 AC 3 ms
6,940 KB
testcase_36 AC 4 ms
6,940 KB
testcase_37 AC 3 ms
6,944 KB
testcase_38 AC 6 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 3 ms
6,940 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 2 ms
6,944 KB
testcase_44 AC 2 ms
6,940 KB
testcase_45 AC 8 ms
6,940 KB
testcase_46 AC 6 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 3 ms
6,944 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 2 ms
6,940 KB
testcase_52 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2389.cc:  No.2389 Cheating Code Golf - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_N = 12;
const int NBITS = 1 << MAX_N;
const int MAX_M = 40;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N], ps[MAX_N];
double invas[MAX_N], invbs[MAX_N], invps[MAX_N];
double dp[NBITS][MAX_M + 1];

/* subroutines */

inline void setmax(double &a, double b) { if (a < b) a = b; }

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d%d%d", as + i, bs + i, ps + i);

  for (int i = 0; i < n; i++) {
    invas[i] = 1.0 / as[i], invbs[i] = 1.0 / bs[i];
    invps[i] = 1.0 / ps[i];
  }

  int nbits = 1 << n;

  for (int bits = 0; bits < nbits; bits++)
    for (int i = 0; i <= m; i++) {
      for (int j = 0, bj = 1; j < n; j++, bj <<= 1)
	if (bits & bj) {
	  setmax(dp[bits][i], dp[bits ^ bj][i] + invas[j]);
	  if (i > 0)
	    setmax(dp[bits][i],
		   (dp[bits ^ bj][i] + invbs[j]) * invps[j] +
		   dp[bits][i - 1] * (1.0 - invps[j]));
	}
    }

  printf("%.12lf\n", dp[nbits - 1][m]);
  
  return 0;
}
0