結果
| 問題 |
No.1688 Veterinarian
|
| コンテスト | |
| ユーザー |
koutykkk
|
| 提出日時 | 2021-09-25 11:32:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 357 ms / 3,000 ms |
| コード長 | 3,297 bytes |
| コンパイル時間 | 2,477 ms |
| コンパイル使用メモリ | 195,580 KB |
| 最終ジャッジ日時 | 2025-01-24 18:06:41 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const int INF = ((1<<30)-1);
const ll LINF = (1LL<<60);
const double PI = 3.141592653589793238;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
double dp[55][55][55][55];
double Com(int n,int k){
double res = 1;
rep(i,0,k){
res *= (n-i);
res /= (k-i);
}
return res;
}
signed main(){
cout << fixed << setprecision(10);
ios::sync_with_stdio(0), cin.tie(0);
int a,b,c,n; cin >> a >> b >> c >> n;
rep(i,0,55)rep(j,0,55)rep(k,0,55)rep(l,0,55)dp[i][j][k][l] = 0;
dp[0][a][b][c] = 1;
rep(i,0,n){
rep(j,0,a+1){
rep(k,0,b+1){
rep(l,0,c+1){
rep(ch1,0,3){
rep(ch2,ch1,3){
if(ch1 == 0 || ch2 == 0){
if(ch2 == ch1 && j < 2)continue;
if(j < 1)continue;
}
if(ch1 == 1 || ch2 == 1){
if(ch2 == ch1 && k < 2)continue;
if(k < 1)continue;
}
if(ch1 == 2 || ch2 == 2){
if(ch2 == ch1 && l < 2)continue;
if(l < 1)continue;
}
double c1 = j;
if(ch1 == 1)c1 = k;
if(ch1 == 2)c1 = l;
double c2 = j;
if(ch2 == 1)c2 = k;
if(ch2 == 2)c2 = l;
if(ch1 == ch2)c2 -= 1;
double tmp = c1 * c2;
if(ch1 == ch2)tmp /= 2;
double kakuritu = tmp / Com(j+k+l , 2);
if(ch1 == ch2){
if(ch1 == 0)dp[i+1][j-1][k][l] += kakuritu * dp[i][j][k][l];
if(ch1 == 1)dp[i+1][j][k-1][l] += kakuritu * dp[i][j][k][l];
if(ch1 == 2)dp[i+1][j][k][l-1] += kakuritu * dp[i][j][k][l];
}
else{
dp[i+1][j][k][l] += kakuritu * dp[i][j][k][l];
}
}
}
}
}
}
}
double ansa = 0, ansb = 0, ansc = 0;
rep(i,0,a+1){
rep(j,0,b+1){
rep(k,0,c+1){
ansa += dp[n][i][j][k] * (a-i);
ansb += dp[n][i][j][k] * (b-j);
ansc += dp[n][i][j][k] * (c-k);
}
}
}
cout << ansa << " " << ansb << " " << ansc << endl;
return 0;
}
koutykkk