結果
問題 | No.108 トリプルカードコンプ |
ユーザー | kagamiz |
提出日時 | 2015-12-06 17:55:20 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 11 ms / 5,000 ms |
コード長 | 827 bytes |
コンパイル時間 | 1,227 ms |
コンパイル使用メモリ | 157,816 KB |
実行使用メモリ | 20,096 KB |
最終ジャッジ日時 | 2024-09-14 16:00:29 |
合計ジャッジ時間 | 2,271 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d", &N); | ~~~~~^~~~~~~~~~ main.cpp:31:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | scanf("%d", &x); | ~~~~~^~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; int N; double memo[128][128][128]; double calc(int zero, int one, int two) { if (zero + one + two == 0) return (0); if (memo[zero][one][two] >= 0) return (memo[zero][one][two]); double ret = 1; if (zero) ret += zero * 1. / N * calc(zero - 1, one + 1, two); if (one) ret += one * 1. / N * calc(zero, one - 1, two + 1); if (two) ret += two * 1. / N * calc(zero, one, two - 1); ret *= N * 1. / (zero + one + two); return (memo[zero][one][two] = ret); } int main() { int ct[3] = {0}; scanf("%d", &N); for (int i = 0; i < N; i++){ int x; scanf("%d", &x); if (x < 3) ct[x]++; } for (int i = 0; i < 128; i++) for (int j = 0; j < 128; j++) for (int k = 0; k < 128; k++) memo[i][j][k] = -1; printf("%.10lf\n", calc(ct[0], ct[1], ct[2])); return (0); }