Datasets:

problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
9 values
p03168
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; double p[n]; for (int i = 0; i < n; i++) { cin >> p[i]; } double dp[n + 1][n + 1]; memset(dp, 0.0, sizeof(dp)); dp[0][0] = 1.0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { if (j == 0) { dp[i][j] = dp[i - 1][j] * (1.0 - p[i - 1]); } else { dp[i][j] = dp[i - 1][j] * (1.0 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]; } } } double prob = 0.0; for (int j = n / 2 + 1; j <= n; j++) { prob += dp[n][j]; } cout << prob << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; double p[n]; for (int i = 0; i < n; i++) { cin >> p[i]; } double dp[n + 1][n + 1]; memset(dp, 0.0, sizeof(dp)); dp[0][0] = 1.0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { if (j == 0) { dp[i][j] = dp[i - 1][j] * (1.0 - p[i - 1]); } else { dp[i][j] = dp[i - 1][j] * (1.0 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]; } } } double prob = 0.0; for (int j = n / 2 + 1; j <= n; j++) { prob += dp[n][j]; } cout << setprecision(10) << prob << endl; return 0; }
[ "io.output.change" ]
977,405
977,406
u362252986
cpp
p03168
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define is(a, b) a == b #define len(v) ll(v.size()) const ll INF = 1LL << 58; // xより以下の要素へのindex template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; } // x以上の要素へのindex template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } int comb(int n, int k) { int ans = 1; FOR(i, n - k + 1, n + 1) { ans *= i; } FOR(i, 1, k + 1) { ans /= i; } return ans; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<ld> p(n); //表の確率 vector<ld> q(n); //裏の確率 vector<vector<ld>> dp( n + 1, vector<ld>(n + 1)); // dp[i+1][j+1]←i番目のまでのコインを投げた時にj枚表 rep(i, n) { cin >> p[i]; q[i] = 1 - p[i]; } dp[1][0] = q[0]; dp[1][1] = p[0]; FOR(i, 2, n + 1) { // j=0の時は全部裏 dp[i][0] = dp[i - 1][0] * q[i - 1]; } FOR(i, 1, n) { rep(j, i + 2) { dp[i + 1][j] = dp[i][j - 1] * p[i] + dp[i][j] * q[i]; } } ld ans = 0; FOR(i, (n + 1) / 2, n + 1) { ans += dp[n][i]; } cout << setprecision(10) << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define is(a, b) a == b #define len(v) ll(v.size()) const ll INF = 1LL << 58; // xより以下の要素へのindex template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; } // x以上の要素へのindex template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } int comb(int n, int k) { int ans = 1; FOR(i, n - k + 1, n + 1) { ans *= i; } FOR(i, 1, k + 1) { ans /= i; } return ans; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<double> p(n); //表の確率 vector<double> q(n); //裏の確率 vector<vector<double>> dp( n + 1, vector<double>( n + 1)); // dp[i+1][j+1]←i番目のまでのコインを投げた時にj枚表 rep(i, n) { cin >> p[i]; q[i] = 1 - p[i]; } dp[1][0] = q[0]; dp[1][1] = p[0]; FOR(i, 2, n + 1) { // j=0の時は全部裏 dp[i][0] = dp[i - 1][0] * q[i - 1]; } FOR(i, 1, n) { rep(j, i + 2) { dp[i + 1][j] = dp[i][j - 1] * p[i] + dp[i][j] * q[i]; } } ld ans = 0; FOR(i, (n + 1) / 2, n + 1) { ans += dp[n][i]; } cout << setprecision(10) << ans << endl; }
[ "call.arguments.change" ]
977,416
977,417
u340010271
cpp
p03168
#include <algorithm> #include <cctype> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); std::cout << fixed << setprecision(10); int n; cin >> n; vector<double> dp((n + 1) / 2, 0); dp[0] = 1.0; for (int i = 0; i < n; i++) { double p; cin >> p; p = 1 - p; for (int j = min(i + 1, (n + 1) / 2); j > 0; j--) { dp[j] = dp[j] * (1 - p) + dp[j - 1] * p; } dp[0] = dp[0] * (1 - p); } cout << accumulate(dp.begin(), dp.end(), 0.0); return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); std::cout << fixed << setprecision(10); int n; cin >> n; vector<double> dp((n + 1) / 2, 0); dp[0] = 1.0; for (int i = 0; i < n; i++) { double p; cin >> p; p = 1 - p; for (int j = min(i + 1, n / 2); j > 0; j--) { dp[j] = dp[j] * (1 - p) + dp[j - 1] * p; } dp[0] = dp[0] * (1 - p); } cout << accumulate(dp.begin(), dp.end(), 0.0); return 0; }
[ "call.arguments.change", "control_flow.loop.for.initializer.change" ]
977,423
977,424
u834415466
cpp
p03168
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<double>> dp(n + 1, vector<double>(n + 1)); dp[0][0] = 1; for (int i = 1; i <= n; ++i) { double p; cin >> p; for (int j = 0; j <= i; ++j) { if (j != 0) { dp[i][j] += dp[i - 1][j - 1] * p; } dp[i][j] += dp[i - 1][j] * (1 - p); } } double ans = 0; for (int i = 0; i <= n; ++i) { int j = n - i; if (i > j) { ans += dp[n][i]; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<double>> dp(n + 1, vector<double>(n + 1)); dp[0][0] = 1; for (int i = 1; i <= n; ++i) { double p; cin >> p; for (int j = 0; j <= i; ++j) { if (j != 0) { dp[i][j] += dp[i - 1][j - 1] * p; } dp[i][j] += dp[i - 1][j] * (1 - p); } } double ans = 0; for (int i = 0; i <= n; ++i) { int j = n - i; if (i > j) { ans += dp[n][i]; } } cout << setprecision(10) << ans; return 0; }
[ "io.output.change" ]
977,425
977,426
u995090660
cpp
p03168
// // ROIGold.cpp // Main calisma // // Created by Rakhman on 05/02/2019. // Copyright © 2019 Rakhman. All rights reserved. // #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> #define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0); #define S second #define F first #define pb push_back #define nl '\n' #define NL cout << '\n'; #define EX exit(0) #define all(s) s.begin(), s.end() #define no_answer return cout << "NO", 0; #define FOR(i, start, finish, k) for (int i = start; i <= finish; i += k) const int MXN = 1e5 + 200; const long long MNN = 3e3 + 200; const long long MOD = 1e9 + 7; const long long INF = 1e13; const int OO = 1e9 + 500; typedef long long llong; typedef unsigned long long ullong; using namespace std; llong n, k; double b[MXN], dp[MXN], ans; void add(llong &a, llong b) { a += b; while (a < 0) a += MOD; a %= MOD; } int main() { ios; cin >> n; dp[0] = 1; for (int i = 1; i <= n; i++) { cin >> b[i]; for (int j = i; j >= 0; j--) { dp[j] = (j == 0 ? 0 : dp[j - 1] * b[i]) + (dp[j] * (1 - b[i])); } } for (int i = 1; i <= n; i++) { if (i > n - i) { ans += dp[i]; } } cout << fixed << setprecision(2) << ans; }
// // ROIGold.cpp // Main calisma // // Created by Rakhman on 05/02/2019. // Copyright © 2019 Rakhman. All rights reserved. // #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> #define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0); #define S second #define F first #define pb push_back #define nl '\n' #define NL cout << '\n'; #define EX exit(0) #define all(s) s.begin(), s.end() #define no_answer return cout << "NO", 0; #define FOR(i, start, finish, k) for (int i = start; i <= finish; i += k) const int MXN = 1e5 + 200; const long long MNN = 3e3 + 200; const long long MOD = 1e9 + 7; const long long INF = 1e13; const int OO = 1e9 + 500; typedef long long llong; typedef unsigned long long ullong; using namespace std; llong n, k; double b[MXN], dp[MXN], ans; void add(llong &a, llong b) { a += b; while (a < 0) a += MOD; a %= MOD; } int main() { ios; cin >> n; dp[0] = 1; for (int i = 1; i <= n; i++) { cin >> b[i]; for (int j = i; j >= 0; j--) { dp[j] = (j == 0 ? 0 : dp[j - 1] * b[i]) + (dp[j] * (1 - b[i])); } } for (int i = 1; i <= n; i++) { if (i > n - i) { ans += dp[i]; } } cout << fixed << setprecision(9) << ans; }
[ "literal.number.change", "io.output.change" ]
977,431
977,432
u796195598
cpp
p03168
#include <algorithm> #include <cassert> #include <functional> #include <iomanip> #include <iostream> #include <vector> int MOD = 1e9 + 7; using namespace std; int main() { int n; cin >> n; vector<double> vec(n); for (int i = 0; i < n; i++) { double x; cin >> x; vec[i] = x; } double dp[n + 1][n + 2]; for (int i = 0; i < 2; i++) { if (i == 0) { dp[1][0] = 1 - vec[0]; } else { dp[1][1] = vec[0]; } } for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { if (j == 0) { dp[i][0] = dp[i][0] * (1 - vec[i - 1]); } else if (j == i) { dp[i][j] = dp[i][j - 1] * vec[i - 1]; } else { dp[i][j] = dp[i - 1][j - 1] * vec[i - 1]; dp[i][j] += dp[i - 1][j] * (1.0 - vec[i - 1]); } } } double res = 0; // cout<<dp[5][5]<<endl; for (int i = n / 2 + 1; i <= n; i++) { res += dp[n][i]; // cout<<dp[n][i]<<endl; } cout << setprecision(10) << res << endl; }
#include <algorithm> #include <cassert> #include <functional> #include <iomanip> #include <iostream> #include <vector> int MOD = 1e9 + 7; using namespace std; int main() { int n; cin >> n; vector<double> vec(n); for (int i = 0; i < n; i++) { double x; cin >> x; vec[i] = x; } double dp[n + 1][n + 2]; for (int i = 0; i < 2; i++) { if (i == 0) { dp[1][0] = 1 - vec[0]; } else { dp[1][1] = vec[0]; } } for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { if (j == 0) { dp[i][0] = dp[i - 1][0] * (1 - vec[i - 1]); } else if (j == i) { dp[i][j] = dp[i - 1][j - 1] * vec[i - 1]; } else { dp[i][j] = dp[i - 1][j - 1] * vec[i - 1]; dp[i][j] += dp[i - 1][j] * (1.0 - vec[i - 1]); } } } double res = 0; // cout<<dp[1][1]<<endl; for (int i = n / 2 + 1; i <= n; i++) { res += dp[n][i]; // cout<<dp[n][i]<<endl; } cout << setprecision(10) << res << endl; }
[ "assignment.change" ]
977,433
977,434
u759162415
cpp
p03168
/* 概率DP,背包模型 dp[i][j]表示前i枚硬币中,有j枚头朝上的概率 */ #include <algorithm> #include <cstdio> #include <vector> #define MAXN 3005 double dp[MAXN][MAXN]; double p[MAXN]; int n; double ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lf", &p[i]); dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); for (int j = 1; j <= n; j++) dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i]; } for (int i = n / 2 + 1; i <= n; i++) ans += dp[n][i]; printf("%g\n", ans); }
/* 概率DP,背包模型 dp[i][j]表示前i枚硬币中,有j枚头朝上的概率 */ #include <algorithm> #include <cstdio> #include <vector> #define MAXN 3005 double dp[MAXN][MAXN]; double p[MAXN]; int n; double ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%lf", &p[i]); dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); for (int j = 1; j <= n; j++) dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i]; } for (int i = n / 2 + 1; i <= n; i++) ans += dp[n][i]; printf("%.10f\n", ans); }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
977,435
977,436
u133805688
cpp
p03168
#include <iostream> using namespace std; #include <bits/stdc++.h> #include <iomanip> #include <string.h> #define ll long long #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define mod 1000000007 double dp[3010][3010] = {}; double rec(double p[], int idx, int heads, int tails) { // if(heads<=tails)return INT_MIN; if (idx < 0 && heads > tails) { return (double)1; } else if (idx < 0) return (double)0; return p[idx] * rec(p, idx - 1, heads + 1, tails) + (1 - p[idx]) * rec(p, idx - 1, heads, tails + 1); } int main() { memset(dp, 0, sizeof(dp)); int n; cin >> n; double p[n]; for (int i = 0; i < n; ++i) { cin >> p[i]; } // cout << rec(p, n-1, 0,0) << endl; dp[0][0] = 1 - p[0]; dp[0][1] = p[0]; for (int i = 1; i < n; ++i) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); } for (int i = 1; i < n; ++i) { for (int j = 1; j <= i + 1; ++j) { dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * (dp[i - 1][j]); } } double ans = 0; for (int i = n / 2 + 1; i <= n; ++i) { ans += dp[n - 1][i]; } cout << setprecision(6); cout << ans << endl; }
#include <iostream> using namespace std; #include <bits/stdc++.h> #include <iomanip> #include <string.h> #define ll long long #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define mod 1000000007 double dp[3001][3001] = {}; double rec(double p[], int idx, int heads, int tails) { // if(heads<=tails)return INT_MIN; if (idx < 0 && heads > tails) { return (double)1; } else if (idx < 0) return (double)0; return p[idx] * rec(p, idx - 1, heads + 1, tails) + (1 - p[idx]) * rec(p, idx - 1, heads, tails + 1); } int main() { memset(dp, 0, sizeof(dp)); int n; cin >> n; double p[n]; for (int i = 0; i < n; ++i) { cin >> p[i]; } // cout << rec(p, n-1, 0,0) << endl; dp[0][0] = 1 - p[0]; dp[0][1] = p[0]; for (int i = 1; i < n; ++i) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); } for (int i = 1; i < n; ++i) { for (int j = 1; j <= i + 1; ++j) { dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * (dp[i - 1][j]); } } double ans = 0.0; for (int i = n / 2 + 1; i <= n; ++i) { ans += dp[n - 1][i]; } cout << setprecision(10); cout << ans << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "variable_declaration.value.change", "io.output.change" ]
977,447
977,448
u088730629
cpp
p03168
#include <iostream> using namespace std; #include <bits/stdc++.h> #include <iomanip> #include <string.h> #define ll long long #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define mod 1000000007 double dp[3000][3000] = {}; double rec(double p[], int idx, int heads, int tails) { // if(heads<=tails)return INT_MIN; if (idx < 0 && heads > tails) { return (double)1; } else if (idx < 0) return (double)0; return p[idx] * rec(p, idx - 1, heads + 1, tails) + (1 - p[idx]) * rec(p, idx - 1, heads, tails + 1); } int main() { memset(dp, 0, sizeof(dp)); int n; cin >> n; double p[n]; for (int i = 0; i < n; ++i) { cin >> p[i]; } // cout << rec(p, n-1, 0,0) << endl; dp[0][0] = 1 - p[0]; dp[0][1] = p[0]; for (int i = 1; i < n; ++i) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); } for (int i = 1; i < n; ++i) { for (int j = 1; j <= i + 1; ++j) { dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * (dp[i - 1][j]); } } double ans = 0; for (int i = n / 2 + 1; i <= n; ++i) { ans += dp[n - 1][i]; } cout << setprecision(6); cout << ans << endl; }
#include <iostream> using namespace std; #include <bits/stdc++.h> #include <iomanip> #include <string.h> #define ll long long #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define mod 1000000007 double dp[3001][3001] = {}; double rec(double p[], int idx, int heads, int tails) { // if(heads<=tails)return INT_MIN; if (idx < 0 && heads > tails) { return (double)1; } else if (idx < 0) return (double)0; return p[idx] * rec(p, idx - 1, heads + 1, tails) + (1 - p[idx]) * rec(p, idx - 1, heads, tails + 1); } int main() { memset(dp, 0, sizeof(dp)); int n; cin >> n; double p[n]; for (int i = 0; i < n; ++i) { cin >> p[i]; } // cout << rec(p, n-1, 0,0) << endl; dp[0][0] = 1 - p[0]; dp[0][1] = p[0]; for (int i = 1; i < n; ++i) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); } for (int i = 1; i < n; ++i) { for (int j = 1; j <= i + 1; ++j) { dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * (dp[i - 1][j]); } } double ans = 0.0; for (int i = n / 2 + 1; i <= n; ++i) { ans += dp[n - 1][i]; } cout << setprecision(10); cout << ans << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "variable_declaration.value.change", "io.output.change" ]
977,449
977,448
u088730629
cpp
p03168
#include <bits/stdc++.h> using namespace std; int n; double p[3030], dp[3030][3030], ans = 0; void pri() { for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) cout << dp[i][j] << ", "; cout << endl; } cout << endl; } int main() { cout << fixed << setprecision(3); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; dp[1][0] = p[1]; dp[0][1] = 1 - p[1]; dp[0][0] = 1; for (int i = 2; i <= n; i++) dp[i][0] = p[i] * dp[i - 1][0]; for (int i = 2; i <= n; i++) dp[0][i] = (1 - p[i]) * dp[0][i - 1]; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { if (i + j > n) continue; dp[i][j] += (p[i + j] * dp[i - 1][j] + (1 - p[i + j]) * dp[i][j - 1]); if (i > j and i + j == n) ans += dp[i][j]; } // pri(); cout << ans + dp[n][0]; return 0; }
#include <bits/stdc++.h> using namespace std; int n; double p[3030], dp[3030][3030], ans = 0; void pri() { for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) cout << dp[i][j] << ", "; cout << endl; } cout << endl; } int main() { cout << fixed << setprecision(20); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; dp[1][0] = p[1]; dp[0][1] = 1 - p[1]; dp[0][0] = 1; for (int i = 2; i <= n; i++) dp[i][0] = p[i] * dp[i - 1][0]; for (int i = 2; i <= n; i++) dp[0][i] = (1 - p[i]) * dp[0][i - 1]; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { if (i + j > n) continue; dp[i][j] += (p[i + j] * dp[i - 1][j] + (1 - p[i + j]) * dp[i][j - 1]); if (i > j and i + j == n) ans += dp[i][j]; } // pri(); cout << ans + dp[n][0]; return 0; }
[ "literal.number.change", "io.output.change" ]
977,456
977,457
u974098214
cpp
p03168
#include "bits/stdc++.h" #define REP(i, x, y) for (int i = (x); i < (y); i++) #define RREP(i, x, y) for (int i = (y)-1; i >= (x); i--) #define all(x) (x).begin(), (x).end() // #define int long long using namespace std; // conversion inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #define dump(x) cerr << #x << " = " << (x) << endl #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl #else #define eprintf(...) 42 #define dump(x) 42 #define debug(x) 42 #endif typedef long long ll; const ll MOD = 1e9 + 7; void solve(int N, vector<double> &p) { vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0)); dp[0][0] = 1; REP(i, 1, N + 1) { dp[i][0] = dp[i - 1][0] * (1 - p[i - 1]); } REP(i, 1, N + 1) { REP(j, 1, i + 1) { dp[i][j] = dp[i - 1][j - 1] * p[i - 1] + dp[i - 1][j] * (1.0 - p[i - 1]); } } double answer = 0; REP(i, (N + 1) / 2, N + 1) { answer += dp[N][i]; } stringstream ss; ss << answer; cout << ss.str() << '\n'; return; } signed main() { int N; cin >> N; vector<double> A(N); REP(i, 0, N) cin >> A[i]; solve(N, A); return 0; }
#include "bits/stdc++.h" #define REP(i, x, y) for (int i = (x); i < (y); i++) #define RREP(i, x, y) for (int i = (y)-1; i >= (x); i--) #define all(x) (x).begin(), (x).end() // #define int long long using namespace std; // conversion inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #define dump(x) cerr << #x << " = " << (x) << endl #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl #else #define eprintf(...) 42 #define dump(x) 42 #define debug(x) 42 #endif typedef long long ll; const ll MOD = 1e9 + 7; void solve(int N, vector<double> &p) { vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0)); dp[0][0] = 1; REP(i, 1, N + 1) { dp[i][0] = dp[i - 1][0] * (1 - p[i - 1]); } REP(i, 1, N + 1) { REP(j, 1, i + 1) { dp[i][j] = dp[i - 1][j - 1] * p[i - 1] + dp[i - 1][j] * (1.0 - p[i - 1]); } } double answer = 0; REP(i, (N + 1) / 2, N + 1) { answer += dp[N][i]; } stringstream ss; ss << setprecision(10) << answer; cout << ss.str() << '\n'; return; } signed main() { int N; cin >> N; vector<double> A(N); REP(i, 0, N) cin >> A[i]; solve(N, A); return 0; }
[ "expression.operation.binary.add" ]
977,458
977,459
u535555850
cpp
p03168
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<double> p(N + 1); for (int i = 1; i <= N; i++) cin >> p[i]; vector<vector<double>> dp; dp = vector<vector<double>>(N + 1, vector<double>(N + 1, 0)); dp[0][0] = 1; for (int i = 1; i <= N; i++) { dp[i][0] = 1; for (int j = 1; j <= i; j++) { dp[i][0] *= (1 - p[j]); } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { dp[i][j] = (1 - p[i]) * dp[i - 1][j] + p[i] * dp[i - 1][j - 1]; } } double ans = 0; for (int i = N / 2 + 1; i <= N; i++) { ans += dp[N][i]; } cout << setprecision(5) << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<double> p(N + 1); for (int i = 1; i <= N; i++) cin >> p[i]; vector<vector<double>> dp; dp = vector<vector<double>>(N + 1, vector<double>(N + 1, 0)); dp[0][0] = 1; for (int i = 1; i <= N; i++) { dp[i][0] = 1; for (int j = 1; j <= i; j++) { dp[i][0] *= (1 - p[j]); } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { dp[i][j] = (1 - p[i]) * dp[i - 1][j] + p[i] * dp[i - 1][j - 1]; } } double ans = 0; for (int i = N / 2 + 1; i <= N; i++) { ans += dp[N][i]; } cout << setprecision(12) << ans << endl; }
[ "literal.number.change", "io.output.change" ]
977,460
977,461
u119098168
cpp
p03168
#include <bits/stdc++.h> using namespace std; double dp[3000][3000]; int main() { int n; double p[3001]; cin >> n; for (int i = 0; i < n; i++) { cin >> p[i]; } dp[0][0] = 1; for (int j = 1; j <= n; j++) { dp[0][j] = dp[0][j - 1] * (1 - p[j - 1]); for (int i = 1; i <= j; i++) { dp[i][j] = dp[i - 1][j - 1] * (p[j - 1]) + dp[i][j - 1] * (1 - p[j - 1]); } } double ans = 0; for (int i = n / 2 + 1; i <= n; i++) { ans += dp[i][n]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; double dp[3000][3000]; int main() { int n; double p[3001]; cin >> n; for (int i = 0; i < n; i++) { cin >> p[i]; } dp[0][0] = 1; for (int j = 1; j <= n; j++) { dp[0][j] = dp[0][j - 1] * (1 - p[j - 1]); for (int i = 1; i <= j; i++) { dp[i][j] = dp[i - 1][j - 1] * (p[j - 1]) + dp[i][j - 1] * (1 - p[j - 1]); } } double ans = 0; for (int i = n / 2 + 1; i <= n; i++) { ans += dp[i][n]; } cout << setprecision(9) << ans << endl; return 0; }
[ "io.output.change" ]
977,464
977,465
u107412005
cpp
p03168
#include <bits/stdc++.h> using namespace std; double dp[3001][3001]; // prob of j heads in first i coins int main() { int i, j, n; double p[3001]; cin >> n; for (i = 0; i < n; i++) cin >> p[i]; for (i = 0; i < n; i++) { for (j = 0; j <= i + 1; j++) { if (i == 0) { if (j == 0) dp[i][j] = 1 - p[i]; else dp[i][j] = p[i]; } else if (j == 0) dp[i][j] = dp[i - 1][j] * (1 - p[i]); else dp[i][j] = (dp[i - 1][j - 1] * p[i]) + (dp[i - 1][j] * (1 - p[i])); } } double ans; for (i = n / 2 + 1; i <= n; i++) ans = ans + dp[n - 1][i]; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; double dp[3001][3001]; // prob of j heads in first i coins int main() { int i, j, n; double p[3001]; cin >> n; for (i = 0; i < n; i++) cin >> p[i]; for (i = 0; i < n; i++) { for (j = 0; j <= i + 1; j++) { if (i == 0) { if (j == 0) dp[i][j] = 1 - p[i]; else dp[i][j] = p[i]; } else if (j == 0) dp[i][j] = dp[i - 1][j] * (1 - p[i]); else dp[i][j] = (dp[i - 1][j - 1] * p[i]) + (dp[i - 1][j] * (1 - p[i])); } } double ans; for (i = n / 2 + 1; i <= n; i++) ans = ans + dp[n - 1][i]; cout << setprecision(10) << ans << endl; }
[ "io.output.change" ]
977,468
977,469
u484972704
cpp
p03168
#include <bits/stdc++.h> #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define FORR(i, a, b) for (ll i = (a); i > (b); --i) #define REP(i, n) for (ll i = 0; i < (n); ++i) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) #define dump(x) cout << #x << " = " << (x) << endl; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using P = pair<ll, ll>; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<double> p(N); REP(i, N) cin >> p[i]; vector<vector<double>> dp(N, vector<double>(N + 1, 0)); dp[0][0] = 1 - p[0]; FOR(i, 1, N) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); } dp[0][1] = p[0]; REP(i, N - 1) FOR(j, 1, N + 1) { dp[i + 1][j] = dp[i][j - 1] * p[i + 1] + dp[i][j] * (1 - p[i + 1]); } double ans = 0; for (int j = N; j > double(N) / 2; j--) { ans += dp[N - 1][j]; } // REP(i, N) { // REP(j, N + 1) { cout << dp[i][j] << ' '; } // cout << endl; // } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define FORR(i, a, b) for (ll i = (a); i > (b); --i) #define REP(i, n) for (ll i = 0; i < (n); ++i) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) #define dump(x) cout << #x << " = " << (x) << endl; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; using P = pair<ll, ll>; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<double> p(N); REP(i, N) cin >> p[i]; vector<vector<double>> dp(N, vector<double>(N + 1, 0)); dp[0][0] = 1 - p[0]; FOR(i, 1, N) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); } dp[0][1] = p[0]; REP(i, N - 1) FOR(j, 1, N + 1) { dp[i + 1][j] = dp[i][j - 1] * p[i + 1] + dp[i][j] * (1 - p[i + 1]); } double ans = 0; for (int j = N; j > double(N) / 2; j--) { ans += dp[N - 1][j]; } // REP(i, N) { // REP(j, N + 1) { cout << dp[i][j] << ' '; } // cout << endl; // } cout << setprecision(10) << ans << endl; return 0; }
[ "io.output.change" ]
977,472
977,473
u520129469
cpp
p03168
#include <bits/stdc++.h> using namespace std; using LL = long long; using VI = vector<LL>; using VVI = vector<VI>; using VB = vector<bool>; using VS = vector<string>; using PII = pair<LL, LL>; using VP = vector<PII>; #define PB push_back #define MP make_pair #define SZ(a) LL((a).size()) #define EACH(x, c) for (auto x : (c)) #define ALL(c) (c).begin(), (c).end() #define REVERSE(c) reverse(ALL(c)) #define SORT(c) stable_sort(ALL(c)) #define RSORT(c) stable_sort((c).rbegin(), (c).rend()) #define FSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.first < y.first; }); #define FRSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.first > y.first; }); #define SSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.second < y.second; }); #define SRSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.second > y.second; }); #define FOR(i, a, b) for (LL i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define $(x) \ { cout << #x << " = " << (x) << endl; } int main() { LL N; cin >> N; vector<double> p(N + 1); FOR(i, 1, N + 1) cin >> p[i]; vector<vector<double>> dp( N + 1, vector<double>(N + 1)); // dp[i][j] = prob. of #H = j with first i coins dp[0][0] = 1; FOR(i, 1, N + 1) { FOR(j, 0, i + 1) { dp[i][j] = (j == 0 ? 0.0 : dp[i - 1][j - 1] * p[i]) + dp[i - 1][j] * (1 - p[i]); } } double ans = 0.0; FOR(j, N / 2 + 1, N + 1) ans += dp[N][j]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using LL = long long; using VI = vector<LL>; using VVI = vector<VI>; using VB = vector<bool>; using VS = vector<string>; using PII = pair<LL, LL>; using VP = vector<PII>; #define PB push_back #define MP make_pair #define SZ(a) LL((a).size()) #define EACH(x, c) for (auto x : (c)) #define ALL(c) (c).begin(), (c).end() #define REVERSE(c) reverse(ALL(c)) #define SORT(c) stable_sort(ALL(c)) #define RSORT(c) stable_sort((c).rbegin(), (c).rend()) #define FSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.first < y.first; }); #define FRSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.first > y.first; }); #define SSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.second < y.second; }); #define SRSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.second > y.second; }); #define FOR(i, a, b) for (LL i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define $(x) \ { cout << #x << " = " << (x) << endl; } int main() { LL N; cin >> N; vector<double> p(N + 1); FOR(i, 1, N + 1) cin >> p[i]; vector<vector<double>> dp( N + 1, vector<double>(N + 1)); // dp[i][j] = prob. of #H = j with first i coins dp[0][0] = 1; FOR(i, 1, N + 1) { FOR(j, 0, i + 1) { dp[i][j] = (j == 0 ? 0.0 : dp[i - 1][j - 1] * p[i]) + dp[i - 1][j] * (1 - p[i]); } } double ans = 0.0; FOR(j, N / 2 + 1, N + 1) ans += dp[N][j]; cout << setprecision(10) << ans << endl; return 0; }
[ "io.output.change" ]
977,474
977,475
u816800341
cpp
p03168
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (n); i++) const int maxn = 3000; double dp[maxn][maxn]; signed main() { int n; cin >> n; vector<double> p(n); for (auto &&u : p) cin >> u; fill(dp[0], dp[maxn], 0.0); dp[0][0] = 1.0; rep(i, n) rep(j, n) { dp[i + 1][j] += dp[i][j] * (1 - p[i]); dp[i + 1][j + 1] += dp[i][j] * (p[i]); } double ret = 0.0; for (int i = n / 2 + 1; i <= n; i++) ret += dp[n][i]; cout << ret << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (n); i++) const int maxn = 3000; double dp[maxn][maxn]; signed main() { int n; cin >> n; vector<double> p(n); for (auto &&u : p) cin >> u; fill(dp[0], dp[maxn], 0.0); dp[0][0] = 1.0; rep(i, n) rep(j, n) { dp[i + 1][j] += dp[i][j] * (1 - p[i]); dp[i + 1][j + 1] += dp[i][j] * (p[i]); } double ret = 0.0; for (int i = n / 2 + 1; i <= n; i++) ret += dp[n][i]; cout << setprecision(10) << ret << endl; }
[ "io.output.change" ]
977,476
977,477
u731175398
cpp
p03168
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <typename T> ostream &operator<<(ostream &os, vector<T> v) { for (auto &i : v) os << i << " "; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &i : v) is >> i; return is; } template <typename K, typename V> ostream &operator<<(ostream &os, unordered_map<K, V> m) { for (auto &i : m) os << i.first << ":" << i.second << endl; return os; } template <typename T> inline bool chmin(T &x, T y) { if (x > y) { x = y; return true; } return false; } template <typename T> inline bool chmax(T &x, T y) { if (x < y) { x = y; return true; } return false; } int main() { int n; cin >> n; vector<double> p(n); cin >> p; vector<vector<double>> dp(n + 1, vector<double>(n + 1)); dp[0][0] = 1.; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { dp[i + 1][j + 1] = dp[i][j] * p[i]; dp[i + 1][j] = dp[i][j] * (1. - p[i]); } } double res = 0.; for (int i = (n + 1) / 2; i <= n; i++) { res += dp[n][i]; } cout << fixed << setprecision(10) << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <typename T> ostream &operator<<(ostream &os, vector<T> v) { for (auto &i : v) os << i << " "; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &i : v) is >> i; return is; } template <typename K, typename V> ostream &operator<<(ostream &os, unordered_map<K, V> m) { for (auto &i : m) os << i.first << ":" << i.second << endl; return os; } template <typename T> inline bool chmin(T &x, T y) { if (x > y) { x = y; return true; } return false; } template <typename T> inline bool chmax(T &x, T y) { if (x < y) { x = y; return true; } return false; } int main() { int n; cin >> n; vector<double> p(n); cin >> p; vector<vector<double>> dp(n + 1, vector<double>(n + 1)); dp[0][0] = 1.; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { dp[i + 1][j + 1] += dp[i][j] * p[i]; dp[i + 1][j] += dp[i][j] * (1. - p[i]); } } double res = 0.; for (int i = (n + 1) / 2; i <= n; i++) { res += dp[n][i]; } cout << fixed << setprecision(10) << res << endl; return 0; }
[ "assignment.value.change" ]
977,478
977,479
u171804186
cpp
p03168
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <typename T> ostream &operator<<(ostream &os, vector<T> v) { for (auto &i : v) os << i << " "; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &i : v) is >> i; return is; } template <typename K, typename V> ostream &operator<<(ostream &os, unordered_map<K, V> m) { for (auto &i : m) os << i.first << ":" << i.second << endl; return os; } template <typename T> inline bool chmin(T &x, T y) { if (x > y) { x = y; return true; } return false; } template <typename T> inline bool chmax(T &x, T y) { if (x < y) { x = y; return true; } return false; } int main() { int n; cin >> n; vector<double> p(n); cin >> p; vector<vector<double>> dp(n + 1, vector<double>(n + 1)); dp[0][0] = 1.; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { dp[i + 1][j + 1] = dp[i][j] * p[i]; dp[i + 1][j] = dp[i][j] * (1. - p[i]); } } double res = 0.; for (int i = (n - 1) / 2; i <= n; i++) { res += dp[n][i]; } cout << fixed << setprecision(10) << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; template <typename T> ostream &operator<<(ostream &os, vector<T> v) { for (auto &i : v) os << i << " "; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &i : v) is >> i; return is; } template <typename K, typename V> ostream &operator<<(ostream &os, unordered_map<K, V> m) { for (auto &i : m) os << i.first << ":" << i.second << endl; return os; } template <typename T> inline bool chmin(T &x, T y) { if (x > y) { x = y; return true; } return false; } template <typename T> inline bool chmax(T &x, T y) { if (x < y) { x = y; return true; } return false; } int main() { int n; cin >> n; vector<double> p(n); cin >> p; vector<vector<double>> dp(n + 1, vector<double>(n + 1)); dp[0][0] = 1.; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { dp[i + 1][j + 1] += dp[i][j] * p[i]; dp[i + 1][j] += dp[i][j] * (1. - p[i]); } } double res = 0.; for (int i = (n + 1) / 2; i <= n; i++) { res += dp[n][i]; } cout << fixed << setprecision(10) << res << endl; return 0; }
[ "assignment.value.change", "misc.opposites", "expression.operator.arithmetic.change", "control_flow.loop.for.initializer.change", "expression.operation.binary.change" ]
977,480
977,479
u171804186
cpp
p03168
#include <bits/stdc++.h> using namespace std; #define ops cout << "ops" << endl; #define freopens \ freopen("cowpatibility.in", "r", stdin); \ freopen("cowpatibility.out", "w", stdout); #define fast \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define DIM 3007 #define DIMM 100007 #define INF 1000000000007.0 #define X (ll)(1 << 32) #define eps 0.0000001 #define PI 3.14159265358979323846 #define MAX 25 #define MODULO (long long)1000000007 const long double gr = (1 + sqrt(5)) / 2; typedef int I; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<I, I> pII; typedef pair<ll, ll> pllll; typedef pair<ld, ld> pldld; typedef vector<I> vI; typedef vector<ll> vll; typedef vector<pllll> vpllll; typedef char cr; typedef string str; ll n; ld a[DIM], dp[DIM][DIM]; ld res; int main() { // ops; // freopens; fast; // ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; dp[0][0] = 1.0; dp[1][1] = a[1]; dp[1][0] = 1.0 - a[1]; for (int i = 2; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1.0 - a[i]); for (int j = 1; j <= i; j++) dp[i][j] = (dp[i - 1][j - 1] * a[i]) + (dp[i - 1][j] * (1.0 - a[i])); } for (int j = 0; (2 * j) <= n; j++) res += dp[n][n - j]; cout << fixed << setprecision(3) << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ops cout << "ops" << endl; #define freopens \ freopen("cowpatibility.in", "r", stdin); \ freopen("cowpatibility.out", "w", stdout); #define fast \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define DIM 3007 #define DIMM 100007 #define INF 1000000000007.0 #define X (ll)(1 << 32) #define eps 0.0000001 #define PI 3.14159265358979323846 #define MAX 25 #define MODULO (long long)1000000007 const long double gr = (1 + sqrt(5)) / 2; typedef int I; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<I, I> pII; typedef pair<ll, ll> pllll; typedef pair<ld, ld> pldld; typedef vector<I> vI; typedef vector<ll> vll; typedef vector<pllll> vpllll; typedef char cr; typedef string str; ll n; ld a[DIM], dp[DIM][DIM]; ld res; int main() { // ops; // freopens; fast; // ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; dp[0][0] = 1.0; dp[1][1] = a[1]; dp[1][0] = 1.0 - a[1]; for (int i = 2; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1.0 - a[i]); for (int j = 1; j <= i; j++) dp[i][j] = (dp[i - 1][j - 1] * a[i]) + (dp[i - 1][j] * (1.0 - a[i])); } for (int j = 0; (2 * j) <= n; j++) res += dp[n][n - j]; cout << fixed << setprecision(10) << res << endl; return 0; }
[ "literal.number.change", "io.output.change" ]
977,488
977,489
u113008684
cpp
p03168
// https://atcoder.jp/contests/dp/tasks/dp_i #include <algorithm> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; #define lengthof(x) (sizeof(x) / sizeof(*(x))) #define EPS (1e-7) #define INF (1e9) #define MODI (1000000007) typedef long long ll; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; // dp[i][j] : コインをi枚使い、j枚が表である確率 // double dp[3001][3001]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; // 入力、DP後、DP前 vector<double> p(n), dpA(n, 0), dpB(n, 0); for (int i = 0; i < n; i++) { cin >> p[i]; } dpB[0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { // i-1回目で表の枚数がj-1で、i回目が表 // i-1回目で表の枚数がjで、i回目が裏 dpA[j] = dpB[j - 1] * p[i - 1] + dpB[j] * (1.0 - p[i - 1]); } swap(dpB, dpA); } double ans = 0; for (int i = n / 2 + 1; i <= n; i++) { ans += dpB[i]; } printf("%0.10f\n", ans); return 0; }
// https://atcoder.jp/contests/dp/tasks/dp_i #include <algorithm> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; #define lengthof(x) (sizeof(x) / sizeof(*(x))) #define EPS (1e-7) #define INF (1e9) #define MODI (1000000007) typedef long long ll; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; // dp[i][j] : コインをi枚使い、j枚が表である確率 // double dp[3001][3001]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; // 入力、DP後、DP前 vector<double> p(n), dpA(n + 1, 0), dpB(n + 1, 0); for (int i = 0; i < n; i++) { cin >> p[i]; } dpB[0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { // i-1回目で表の枚数がj-1で、i回目が表 // i-1回目で表の枚数がjで、i回目が裏 dpA[j] = dpB[j - 1] * p[i - 1] + dpB[j] * (1.0 - p[i - 1]); } swap(dpB, dpA); } double ans = 0; for (int i = n / 2 + 1; i <= n; i++) { ans += dpB[i]; } printf("%0.10f\n", ans); return 0; }
[ "assignment.change" ]
977,493
977,494
u858107870
cpp
p03168
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second typedef long long ll; typedef long double ld; typedef pair<int, int> pi; const int MOD = 1e9 + 7; const ll INF = 1e18; const double EPS = 1e-6; const int MAX_N = 3005; int N; double prob[MAX_N]; double dp[MAX_N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; for (int i = 1; i <= N; ++i) { cin >> prob[i]; } dp[0] = 0; for (int i = 1; i <= N; ++i) { for (int j = i; j >= 0; --j) { dp[j] = (j == 0 ? 0 : dp[j - 1] * prob[i]) + dp[j] * (1 - prob[i]); } } double ans = 0; for (int i = 0; i <= N; ++i) { int tails = N - i; if (i > tails) ans += dp[i]; } cout << fixed << setprecision(30) << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second typedef long long ll; typedef long double ld; typedef pair<int, int> pi; const int MOD = 1e9 + 7; const ll INF = 1e18; const double EPS = 1e-6; const int MAX_N = 3005; int N; double prob[MAX_N]; double dp[MAX_N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N; for (int i = 1; i <= N; ++i) { cin >> prob[i]; } dp[0] = 1; for (int i = 1; i <= N; ++i) { for (int j = i; j >= 0; --j) { dp[j] = (j == 0 ? 0 : dp[j - 1] * prob[i]) + dp[j] * (1 - prob[i]); } } double ans = 0; for (int i = 0; i <= N; ++i) { int tails = N - i; if (i > tails) ans += dp[i]; } cout << fixed << setprecision(30) << ans << '\n'; return 0; }
[ "literal.number.change", "assignment.value.change" ]
977,508
977,509
u738069880
cpp
p03168
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef vector<int> vi; #define PI 3.14159265 #define int long long #define f first #define s second #define mtup make_tuple #define nl '\n' #define FLASH \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define maxheap priority_queue<ll> #define minheap priority_queue<ll, vector<ll>, greater<ll>> const ll inf = 1e18 + 1; const int mod = 1e9 + 7; const int maxn = 5e6; ll modpow(ll a, ll b, int mod = inf) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int gcd(int a, int b) { return __gcd(a, b); } int n; long double h[3333], t[3333], dp[3333][3333]; signed main() { FLASH memset(dp, 0, sizeof(dp)); cin >> n; for (int i = 1; i <= n; i++) cin >> h[i], t[i] = 1 - h[i]; dp[1][1] = h[1]; dp[0][1] = t[1]; for (int i = 2; i <= n; i++) dp[0][i] = t[i] * dp[0][i - 1]; for (int j = 2; j <= n; j++) for (int i = 1; i <= j; i++) dp[i][j] = dp[i][j - 1] * t[j] + dp[i - 1][j - 1] * h[j]; long double p = 0; for (int i = 1 + n / 2; i <= n; i++) p += dp[i][n]; cout << p << nl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef vector<int> vi; #define PI 3.14159265 #define int long long #define f first #define s second #define mtup make_tuple #define nl '\n' #define FLASH \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define maxheap priority_queue<ll> #define minheap priority_queue<ll, vector<ll>, greater<ll>> const ll inf = 1e18 + 1; const int mod = 1e9 + 7; const int maxn = 5e6; ll modpow(ll a, ll b, int mod = inf) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } int gcd(int a, int b) { return __gcd(a, b); } int n; long double h[3333], t[3333], dp[3333][3333]; signed main() { FLASH memset(dp, 0, sizeof(dp)); cin >> n; for (int i = 1; i <= n; i++) cin >> h[i], t[i] = 1 - h[i]; dp[1][1] = h[1]; dp[0][1] = t[1]; for (int i = 2; i <= n; i++) dp[0][i] = t[i] * dp[0][i - 1]; for (int j = 2; j <= n; j++) for (int i = 1; i <= j; i++) dp[i][j] = dp[i][j - 1] * t[j] + dp[i - 1][j - 1] * h[j]; long double p = 0; for (int i = 1 + n / 2; i <= n; i++) p += dp[i][n]; cout << setprecision(10) << p << nl; return 0; }
[ "io.output.change" ]
977,516
977,517
u687041259
cpp
p03168
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long double> f(n + 1); f[0] = 1; for (int i = 0; i < n; i++) { long double p0; cin >> p0; for (int j = n - 1; j >= 0; j--) { f[j + 1] += p0 * f[j]; f[j] += (1 - p0) * f[j]; } } long double pr = 0; for (int i = (n + 1) / 2; i <= n; i++) pr += f[i]; cout << fixed << setprecision(12) << pr << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<long double> f(n + 1); f[0] = 1; for (int i = 0; i < n; i++) { long double p0; cin >> p0; for (int j = n - 1; j >= 0; j--) { f[j + 1] += p0 * f[j]; f[j] *= (1 - p0); } } long double pr = 0; for (int i = (n + 1) / 2; i <= n; i++) pr += f[i]; cout << fixed << setprecision(12) << pr << endl; return 0; }
[ "expression.operator.change", "expression.operation.binary.remove" ]
977,538
977,539
u251828455
cpp
p03168
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define tr(container, it) \ for (auto it = container.begin(); it != container.end(); it++) #define scontains(c, x) ((c).find(x) != (c).end()) // O(log n) #define contains(c, x) (find((c).begin(), (c).end(), x) != (c).end()) // O(n) #define pll pair<ll, ll> #define pii pair<int, int> #define mll map<ll, ll> #define in(x, a, b) ((x) >= a && (x) <= b) #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1) #define all(x) (x).begin(), (x).end() //#define len(array) (sizeof(array)/sizeof((array)[0])) #define endl '\n' #define what_is(x) cerr << #x << " is " << x << endl; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } #define mod(x, m) ((((x) % (m)) + (m)) % (m)) void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } const double PI = 2 * acos(.0); const int INF = 0x3f3f3f3f; const ll LLINF = 1000000000000000005LL; ; const ll MOD = (ll)(1e9) + 7; // const int mod = 1777777777; const double EPS = 1e-10; int readint() { int x; cin >> x; return x; } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto a : v) os << a << " "; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto a : v) os << a << " "; return os; } int power_mod(int x, int y, int p) { if (y < 0) return 0; int res = 1; x = x % p; while (y) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int power(ll x, ll y) { if (y < 0) return 0; ll res = 1; while (y) { if (y & 1) res = (res * x); y = y >> 1; x *= x; } return res; } int fac[7777777]; void init(int MX) { fac[0] = 1; for (int i = 1; i <= MX; i++) fac[i] = fac[i - 1] * i % MOD; } // Returns n^(-1) mod p int modInverse(int n, int p) { return power_mod(n, p - 2, p); } int comb_mod(int n, int r, int p) { if (r == 0) return 1; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } int comb(int a, int b) { int res = 1; rep(i, a + 1, a - b + 1) res *= i, res /= a - i + 1; // rep(i,1,b+1)res /= i; return res; } bool equal(double a, double b) { return std::fabs(a - b) < std::numeric_limits<double>::epsilon(); } struct UnionFind { // par[i]:データiが属する木の親の番号。i == // par[i]のとき、データiは木の根ノードである vector<int> par; // sizes[i]:根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる vector<int> sizes; UnionFind(int n) : par(n), sizes(n, 1) { // 最初は全てのデータiがグループiに存在するものとして初期化 rep(i, 0, n) par[i] = i; } // データxが属する木の根を得る int find(int x) { if (x == par[x]) return x; return par[x] = find(par[x]); // 根を張り替えながら再帰的に根ノードを探す } // 2つのデータx, yが属する木をマージする void unite(int x, int y) { // データの根ノードを得る x = find(x); y = find(y); // 既に同じ木に属しているならマージしない if (x == y) return; // xの木がyの木より大きくなるようにする if (sizes[x] < sizes[y]) swap(x, y); // xがyの親になるように連結する par[y] = x; sizes[x] += sizes[y]; // sizes[y] = 0; // sizes[y]は無意味な値となるので0を入れておいてもよい } // 2つのデータx, yが属する木が同じならtrueを返す bool same(int x, int y) { return find(x) == find(y); } // データxが含まれる木の大きさを返す int size(int x) { return sizes[find(x)]; } }; // fastest struct cpmFunctor { inline bool operator()(const pair<int, int> &p1, const pair<int, int> &p2) { return p1.first < p2.first || (p1.first == p2.first && p1.second < p2.second); } }; bool isPrime(int n) { // Corner case if (n <= 1) return false; if (n == 2 || n == 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; // Check from 2 to n-1 for (int i = 5; i * i <= n; i += 6) if (n % i == 0) return false; for (int i = 7; i * i <= n; i += 6) if (n % i == 0) return false; return true; } int lcm(int a, int b) { return a / __gcd(a, b) * b; } map<int, int> factorize(long long n) { map<int, int> factors; int count = 0; while (!(n % 2)) { n >>= 1; count++; } if (count) factors[2] = count; for (long long i = 3; i <= sqrt(n); i += 2) { count = 0; while (n % i == 0) { count++; n = n / i; } if (count) factors[i] = count; } if (n > 2) factors[n] = 1; return factors; } // class Graph{ // int V; // vector<int>* adj; // // public: // Graph(int V){ // this->V = V; // adj = new vector<int>[V]; // // } // // void addEdge(int from, int to){ // adj[from].push_back(to); // } // // // bool isCyclicUtil(int v, bool visited[], bool *recStack) // { // if(visited[v] == false) // { // // Mark the current node as visited and part of recursion stack // visited[v] = true; // recStack[v] = true; // // // Recur for all the vertices adjacent to this vertex // for(auto i = adj[v].begin(); i != adj[v].end(); ++i) // { // if ( !visited[*i] && isCyclicUtil(*i, visited, recStack) ) // return true; // else if (recStack[*i]) // return true; // } // // } // recStack[v] = false; // remove the vertex from recursion stack // return false; // } // //// Returns true if the graph contains a cycle, else false. //// This function is a variation of DFS() in ///https://www.geeksforgeeks.org/archives/18212 // bool isCyclic() // { // // Mark all the vertices as not visited and not part of recursion // // stack // bool *visited = new bool[V]; // bool *recStack = new bool[V]; // for(int i = 0; i < V; i++) // { // visited[i] = false; // recStack[i] = false; // } // // // Call the recursive helper function to detect cycle in different // // DFS trees // for(int i = 0; i < V; i++) // if (isCyclicUtil(i, visited, recStack)) // return true; // // return false; // } // // //}; struct edge { int to; int cost; }; class wGraph { int V; vector<edge> *adj; public: wGraph(int V) { this->V = V; adj = new vector<edge>[V]; } void addEdge(int from, int to, int cost) { adj[from].push_back({to, cost}); } }; //#define int ll double P[3000][3333]; double p[3033]; double res; int N; void solve() { cin >> N; _for(i, N) cin >> p[i + 1]; P[0][0] = 1.; rep(n, 1, N + 1) { P[0][n] = P[0][n - 1] * (1 - p[n]); P[n][0] = P[n - 1][0] * p[n]; rep(i, 1, n) P[i][n - i] = P[i - 1][n - i] * p[n] + P[i][n - i - 1] * (1 - p[n]); } rep(i, 0, (N + 1) / 2) res += P[N - i][i]; cout << res << endl; } #undef int int main() { #if __MINGW32__ freopen("../Input.txt", "r", stdin); freopen("../Output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define tr(container, it) \ for (auto it = container.begin(); it != container.end(); it++) #define scontains(c, x) ((c).find(x) != (c).end()) // O(log n) #define contains(c, x) (find((c).begin(), (c).end(), x) != (c).end()) // O(n) #define pll pair<ll, ll> #define pii pair<int, int> #define mll map<ll, ll> #define in(x, a, b) ((x) >= a && (x) <= b) #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define _for(i, end) for (__typeof(end) i = 0; i < (end); i += 1) #define all(x) (x).begin(), (x).end() //#define len(array) (sizeof(array)/sizeof((array)[0])) #define endl '\n' #define what_is(x) cerr << #x << " is " << x << endl; #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } #define mod(x, m) ((((x) % (m)) + (m)) % (m)) void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } const double PI = 2 * acos(.0); const int INF = 0x3f3f3f3f; const ll LLINF = 1000000000000000005LL; ; const ll MOD = (ll)(1e9) + 7; // const int mod = 1777777777; const double EPS = 1e-10; int readint() { int x; cin >> x; return x; } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto a : v) os << a << " "; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto a : v) os << a << " "; return os; } int power_mod(int x, int y, int p) { if (y < 0) return 0; int res = 1; x = x % p; while (y) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int power(ll x, ll y) { if (y < 0) return 0; ll res = 1; while (y) { if (y & 1) res = (res * x); y = y >> 1; x *= x; } return res; } int fac[7777777]; void init(int MX) { fac[0] = 1; for (int i = 1; i <= MX; i++) fac[i] = fac[i - 1] * i % MOD; } // Returns n^(-1) mod p int modInverse(int n, int p) { return power_mod(n, p - 2, p); } int comb_mod(int n, int r, int p) { if (r == 0) return 1; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } int comb(int a, int b) { int res = 1; rep(i, a + 1, a - b + 1) res *= i, res /= a - i + 1; // rep(i,1,b+1)res /= i; return res; } bool equal(double a, double b) { return std::fabs(a - b) < std::numeric_limits<double>::epsilon(); } struct UnionFind { // par[i]:データiが属する木の親の番号。i == // par[i]のとき、データiは木の根ノードである vector<int> par; // sizes[i]:根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる vector<int> sizes; UnionFind(int n) : par(n), sizes(n, 1) { // 最初は全てのデータiがグループiに存在するものとして初期化 rep(i, 0, n) par[i] = i; } // データxが属する木の根を得る int find(int x) { if (x == par[x]) return x; return par[x] = find(par[x]); // 根を張り替えながら再帰的に根ノードを探す } // 2つのデータx, yが属する木をマージする void unite(int x, int y) { // データの根ノードを得る x = find(x); y = find(y); // 既に同じ木に属しているならマージしない if (x == y) return; // xの木がyの木より大きくなるようにする if (sizes[x] < sizes[y]) swap(x, y); // xがyの親になるように連結する par[y] = x; sizes[x] += sizes[y]; // sizes[y] = 0; // sizes[y]は無意味な値となるので0を入れておいてもよい } // 2つのデータx, yが属する木が同じならtrueを返す bool same(int x, int y) { return find(x) == find(y); } // データxが含まれる木の大きさを返す int size(int x) { return sizes[find(x)]; } }; // fastest struct cpmFunctor { inline bool operator()(const pair<int, int> &p1, const pair<int, int> &p2) { return p1.first < p2.first || (p1.first == p2.first && p1.second < p2.second); } }; bool isPrime(int n) { // Corner case if (n <= 1) return false; if (n == 2 || n == 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; // Check from 2 to n-1 for (int i = 5; i * i <= n; i += 6) if (n % i == 0) return false; for (int i = 7; i * i <= n; i += 6) if (n % i == 0) return false; return true; } int lcm(int a, int b) { return a / __gcd(a, b) * b; } map<int, int> factorize(long long n) { map<int, int> factors; int count = 0; while (!(n % 2)) { n >>= 1; count++; } if (count) factors[2] = count; for (long long i = 3; i <= sqrt(n); i += 2) { count = 0; while (n % i == 0) { count++; n = n / i; } if (count) factors[i] = count; } if (n > 2) factors[n] = 1; return factors; } // class Graph{ // int V; // vector<int>* adj; // // public: // Graph(int V){ // this->V = V; // adj = new vector<int>[V]; // // } // // void addEdge(int from, int to){ // adj[from].push_back(to); // } // // // bool isCyclicUtil(int v, bool visited[], bool *recStack) // { // if(visited[v] == false) // { // // Mark the current node as visited and part of recursion stack // visited[v] = true; // recStack[v] = true; // // // Recur for all the vertices adjacent to this vertex // for(auto i = adj[v].begin(); i != adj[v].end(); ++i) // { // if ( !visited[*i] && isCyclicUtil(*i, visited, recStack) ) // return true; // else if (recStack[*i]) // return true; // } // // } // recStack[v] = false; // remove the vertex from recursion stack // return false; // } // //// Returns true if the graph contains a cycle, else false. //// This function is a variation of DFS() in ///https://www.geeksforgeeks.org/archives/18212 // bool isCyclic() // { // // Mark all the vertices as not visited and not part of recursion // // stack // bool *visited = new bool[V]; // bool *recStack = new bool[V]; // for(int i = 0; i < V; i++) // { // visited[i] = false; // recStack[i] = false; // } // // // Call the recursive helper function to detect cycle in different // // DFS trees // for(int i = 0; i < V; i++) // if (isCyclicUtil(i, visited, recStack)) // return true; // // return false; // } // // //}; struct edge { int to; int cost; }; class wGraph { int V; vector<edge> *adj; public: wGraph(int V) { this->V = V; adj = new vector<edge>[V]; } void addEdge(int from, int to, int cost) { adj[from].push_back({to, cost}); } }; //#define int ll double P[3000][3333]; double p[3033]; double res; int N; void solve() { cin >> N; _for(i, N) cin >> p[i + 1]; P[0][0] = 1.; rep(n, 1, N + 1) { P[0][n] = P[0][n - 1] * (1 - p[n]); P[n][0] = P[n - 1][0] * p[n]; rep(i, 1, n) P[i][n - i] = P[i - 1][n - i] * p[n] + P[i][n - i - 1] * (1 - p[n]); } rep(i, 0, (N + 1) / 2) res += P[N - i][i]; cout << setprecision(12) << res << endl; } #undef int int main() { #if __MINGW32__ freopen("../Input.txt", "r", stdin); freopen("../Output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
[ "io.output.change" ]
977,542
977,543
u093219895
cpp
p03168
#include <bits/stdc++.h> #define ll long long #define ld long double #define OO 2e18 #define oo 1e9 #define yalla ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define FILES \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define sz 100005 #define re return #define mod 1000000007 #define pi acos(-1) using namespace std; /// int n; /// length,numofheads ld ans[3005][3005], prop[3005], sum; int main() { yalla; cin >> n; for (int i = 1; i <= n; i++) cin >> prop[i]; /// /// number of coins, number of ups ans[1][0] = 1 - prop[1]; ans[1][1] = prop[1]; /// for (int i = 2; i <= n; i++) { for (int y = 0; y <= n; y++) { ans[i][y] += ans[i - 1][y] * (1 - prop[i]); if (y) ans[i][y] += (prop[i] * ans[i - 1][y - 1]); } } for (int i = (n / 2) + 1; i <= n; i++) /// last row sum += ans[n][i]; cout << setprecision(3) << sum << endl; re 0; }
#include <bits/stdc++.h> #define ll long long #define ld long double #define OO 2e18 #define oo 1e9 #define yalla ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define FILES \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define sz 100005 #define re return #define mod 1000000007 #define pi acos(-1) using namespace std; /// int n; /// length,numofheads ld ans[3005][3005], prop[3005], sum; int main() { yalla; cin >> n; for (int i = 1; i <= n; i++) cin >> prop[i]; /// /// number of coins, number of ups ans[1][0] = 1 - prop[1]; ans[1][1] = prop[1]; /// for (int i = 2; i <= n; i++) { for (int y = 0; y <= n; y++) { ans[i][y] += ans[i - 1][y] * (1 - prop[i]); if (y) ans[i][y] += (prop[i] * ans[i - 1][y - 1]); } } for (int i = (n / 2) + 1; i <= n; i++) /// last row sum += ans[n][i]; cout << fixed << setprecision(10) << sum << endl; re 0; }
[ "io.output.change", "literal.number.change" ]
977,552
977,551
u412213585
cpp
p03168
#include <bits/stdc++.h> #define ll long long int #define MOD 1000000007 #define Test \ ll t; \ cin >> t; \ while (t--) #define init(arr, val) memset(arr, val, sizeof(arr)) #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define loopS(i, a, b, step) for (ll i = a; i < b; i += step) #define loopRS(i, a, b, step) for (ll i = a; i >= b; i -= step) #define ull unsigned long long int #define pll pair<ll, ll> #define puu pair<ull, ull> #define V vector #define M map #define UM unordered_map #define mp(x, y) make_pair(x, y) #define pb push_back #define pf push_front #define ff first #define ss second #define inf INT_MAX #define S3(a, b, c) cin >> a >> b >> c #define S2(a, b) cin >> a >> b #define debug(x) cout << #x << " = " << x << endl; using namespace std; void input(ll n, double arr[]) { rep(i, 1, n + 1) cin >> arr[i]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; double pHead[n]; input(n, pHead); double dp[n + 1][n + 1]; init(dp, double(0)); // probability of getting i heads from j tails. dp[0][0] = 1; /*We have two possibilities for the j - th coin. Case 1 - It is a heads. The probability of getting a head is p[j]. And we need to get exactly (i - 1) heads from the previous (j - 1) coins. This is given by p[j] x f(i - 1, j - 1) Case 2 - It is tails The probability is given by (1 - p[j]) We need i heads from the first j - 1 coins. The probability is (1 - p[j]) x f(i, j - 1)*/ rep(i, 1, n + 1) { double t = 1 - pHead[i], p = pHead[i]; // 0 heads hai dp[0][i] = t * (dp[0][i - 1]); rep(head, 1, i + 1) { dp[head][i] = p * dp[head - 1][i - 1] + t * dp[head][i - 1]; } } double ans = 0; rep(i, n / 2 + 1, n + 1) { ans += dp[i][n]; } cout << setprecision(6) << ans; }
#include <bits/stdc++.h> #define ll long long int #define MOD 1000000007 #define Test \ ll t; \ cin >> t; \ while (t--) #define init(arr, val) memset(arr, val, sizeof(arr)) #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define loopS(i, a, b, step) for (ll i = a; i < b; i += step) #define loopRS(i, a, b, step) for (ll i = a; i >= b; i -= step) #define ull unsigned long long int #define pll pair<ll, ll> #define puu pair<ull, ull> #define V vector #define M map #define UM unordered_map #define mp(x, y) make_pair(x, y) #define pb push_back #define pf push_front #define ff first #define ss second #define inf INT_MAX #define S3(a, b, c) cin >> a >> b >> c #define S2(a, b) cin >> a >> b #define debug(x) cout << #x << " = " << x << endl; using namespace std; void input(ll n, double arr[]) { rep(i, 1, n + 1) cin >> arr[i]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; double pHead[n]; input(n, pHead); double dp[n + 1][n + 1]; init(dp, double(0)); // probability of getting i heads from j tails. dp[0][0] = 1; /*We have two possibilities for the j - th coin. Case 1 - It is a heads. The probability of getting a head is p[j]. And we need to get exactly (i - 1) heads from the previous (j - 1) coins. This is given by p[j] x f(i - 1, j - 1) Case 2 - It is tails The probability is given by (1 - p[j]) We need i heads from the first j - 1 coins. The probability is (1 - p[j]) x f(i, j - 1)*/ rep(i, 1, n + 1) { double t = 1 - pHead[i], p = pHead[i]; // 0 heads hai dp[0][i] = t * (dp[0][i - 1]); rep(head, 1, i + 1) { dp[head][i] = p * dp[head - 1][i - 1] + t * dp[head][i - 1]; } } double ans = 0; rep(i, n / 2 + 1, n + 1) { ans += dp[i][n]; } cout << setprecision(9) << ans; }
[ "literal.number.change", "io.output.change" ]
977,553
977,554
u693452116
cpp
p03168
#include <cstdio> #include <iostream> #define MAXN 3500 using namespace std; int n; double answer; double p[MAXN]; double ans[MAXN][MAXN]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; } ans[1][1] = 1 - p[1]; ans[1][2] = p[1]; for (int i = 2; i <= n; i++) { for (int j = 1; j <= n + 1; j++) { ans[i][j] = ans[i - 1][j] * (1 - p[i]) + ans[i - 1][j - 1] * p[i]; } } /*for (int i = 1; i <= n+1; i++){ for (int j = 1; j <= n+1; j++){ cout << ans[j][i] << ' '; } cout << endl; }*/ answer = 0; for (int i = n / 2 + 1; i <= n; i++) { answer += ans[n][i + 1]; // cout << ans[n][i+1] << ' ' << i+1 << ' ' << n << endl; } cout.fixed; cout.precision(3); cout << answer << endl; }
#include <cstdio> #include <iostream> #define MAXN 3500 using namespace std; int n; double answer; double p[MAXN]; double ans[MAXN][MAXN]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> p[i]; } ans[1][1] = 1 - p[1]; ans[1][2] = p[1]; for (int i = 2; i <= n; i++) { for (int j = 1; j <= n + 1; j++) { ans[i][j] = ans[i - 1][j] * (1 - p[i]) + ans[i - 1][j - 1] * p[i]; } } /*for (int i = 1; i <= n+1; i++){ for (int j = 1; j <= n+1; j++){ cout << ans[j][i] << ' '; } cout << endl; }*/ answer = 0; for (int i = n / 2 + 1; i <= n; i++) { answer += ans[n][i + 1]; // cout << ans[n][i+1] << ' ' << i+1 << ' ' << n << endl; } cout.fixed; cout.precision(12); cout << answer << endl; }
[ "literal.number.change", "io.output.change" ]
977,571
977,572
u290335371
cpp
p03168
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll n, i, j; cin >> n; double a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } double dp[n + 1]; dp[0] = 1; for (i = 0; i < n; i++) { for (j = i + 1; j > 0; j--) { dp[j] = (1 - a[i]) * dp[j] + (a[i] * dp[j - 1]); } dp[0] = dp[0] * (1 - a[i]); } double ans = 0; for (i = n; i > n / 2; i--) { ans += dp[i]; } printf("%.12lf\n", ans); }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll n, i, j; cin >> n; double a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } double dp[n + 1] = {0}; dp[0] = 1; for (i = 0; i < n; i++) { for (j = i + 1; j > 0; j--) { dp[j] = (1 - a[i]) * dp[j] + (a[i] * dp[j - 1]); } dp[0] = dp[0] * (1 - a[i]); } double ans = 0; for (i = n; i > n / 2; i--) { ans += dp[i]; } printf("%.12lf\n", ans); }
[ "variable_declaration.value.change" ]
977,575
977,576
u388528458
cpp
p03168
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; double *DP = new double[n + 1]; DP[0] = 1; for (int i = 1; i <= n; i++) DP[i] = 0; for (int i = 0; i < n; i++) { double p; cin >> p; for (int j = i + 1; j > 0; j--) { DP[j] = DP[j] * (1 - p) + DP[j - 1] * p; } DP[0] *= (1 - p); } double ans = 0; for (int i = n; i > n / 2; i--) { ans += DP[i]; } printf("%g\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; double *DP = new double[n + 1]; DP[0] = 1; for (int i = 1; i <= n; i++) DP[i] = 0; for (int i = 0; i < n; i++) { double p; cin >> p; for (int j = i + 1; j > 0; j--) { DP[j] = DP[j] * (1 - p) + DP[j - 1] * p; } DP[0] *= (1 - p); } double ans = 0; for (int i = n; i > n / 2; i--) { ans += DP[i]; } printf("%.10f\n", ans); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
977,578
977,579
u352811222
cpp
p03168
#include <cstdio> double dp[3000][3000]; int main() { int n; scanf("%d", &n); dp[0][0] = 1; for (int i = 1; i <= n; i++) { double p; scanf("%lf", &p); dp[i][0] = dp[i - 1][0] * (1 - p); for (int j = 1; j < i; j++) dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j] * (1 - p); dp[i][i] = dp[i - 1][i - 1] * p; } double ans = 0; for (int i = n; i > n / 2; i++) ans += dp[n][i]; printf("%.10lf", ans); return 0; }
#include <cstdio> double dp[3000][3000]; int main() { int n; scanf("%d", &n); dp[0][0] = 1; for (int i = 1; i <= n; i++) { double p; scanf("%lf", &p); dp[i][0] = dp[i - 1][0] * (1 - p); for (int j = 1; j < i; j++) dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j] * (1 - p); dp[i][i] = dp[i - 1][i - 1] * p; } double ans = 0; for (int i = n; i > n / 2; i--) ans += dp[n][i]; printf("%.10lf", ans); return 0; }
[]
977,590
977,591
u350561621
cpp
p03168
#include <bits/stdc++.h> using namespace std; #define int long long int hell = 1e9 + 7; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, i, j; cin >> n; vector<double> P(n); for (i = 0; i < n; i++) cin >> P[i]; vector<vector<double>> dp(n, vector<double>(n + 1, 0)); // dp[i][j] = probability that among first i+1 coins, j coins are heads dp[0][0] = 1 - P[0]; dp[0][1] = P[0]; for (i = 1; i < n; i++) { dp[i][0] = dp[i - 1][0] * (1 - P[i]); for (j = 1; j <= n; j++) dp[i][j] = (dp[i - 1][j - 1] * P[i]) + (dp[i - 1][j] * (1 - P[i])); } double ans = 0; for (i = (n / 2) + 1; i <= n; i++) ans += dp[n - 1][i]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int hell = 1e9 + 7; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, i, j; cin >> n; vector<double> P(n); for (i = 0; i < n; i++) cin >> P[i]; vector<vector<double>> dp(n, vector<double>(n + 1, 0)); // dp[i][j] = probability that among first i+1 coins, j coins are heads dp[0][0] = 1 - P[0]; dp[0][1] = P[0]; for (i = 1; i < n; i++) { dp[i][0] = dp[i - 1][0] * (1 - P[i]); for (j = 1; j <= n; j++) dp[i][j] = (dp[i - 1][j - 1] * P[i]) + (dp[i - 1][j] * (1 - P[i])); } double ans = 0; for (i = (n / 2) + 1; i <= n; i++) ans += dp[n - 1][i]; cout << setprecision(10) << ans << endl; return 0; }
[ "io.output.change" ]
977,601
977,602
u310367652
cpp
p03168
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdint> #include <cstdlib> #include <iostream> #include <list> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_r(i, n) for (int i = n - 1; i >= 0; i--) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() #define SZ(x) ((ll)(x).size()) #define bit(n) (1LL << (n)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define INF bit(60) #define pb push_back #define mod 1000000007 template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; using uif = uint_fast64_t; using ll = long long int; int qp(int a, ll b) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mod; a = 1ll * a * a % mod; } while (b >>= 1); return ans; } int qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; ll fb[4] = {2, 1, 1, 0}; double next(double p1, double p2, ll ind) { if (ind == 0) return p1 * p2; else if (ind == 1) return (1.0 - p1) * p2; else if (ind == 2) return p1 * (1.0 - p2); // else if(ind==3) return (1.0-p1)*(1.0-p2); else return (1.0 - p1) * (1.0 - p2); } int main(void) { ll n; cin >> n; vector<double> p(n + 1); vector<vector<double>> q(3000, vector<double>(3000, 0.0)); rep1(i, n) { cin >> p[i]; } q[1][0] = p[1]; // round, num o' front q[0][1] = 1.0 - p[1]; for (ll i = 1; i <= n - 2; i += 2) { rep(j, i + 1) { // cout << i-j << "," << j << ":" << endl; rep(k, 4) { // cout << i-j + fb[k] << "," << j + fb[3-k] << endl; // cout << "q:" << q[i-j][j] << "next:" << next(p[i+1],p[i+2],k) << // endl; q[i - j + fb[k]][j + fb[3 - k]] += q[i - j][j] * next(p[i + 1], p[i + 2], k); } } } double ans = 0.0; for (ll i = n; i > n - i; i--) { // cout << i << "," << n-i << endl; ans += q[i][n - i]; } cout << ans << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdint> #include <cstdlib> #include <iostream> #include <list> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_r(i, n) for (int i = n - 1; i >= 0; i--) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() #define SZ(x) ((ll)(x).size()) #define bit(n) (1LL << (n)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define INF bit(60) #define pb push_back #define mod 1000000007 template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; using uif = uint_fast64_t; using ll = long long int; int qp(int a, ll b) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mod; a = 1ll * a * a % mod; } while (b >>= 1); return ans; } int qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; ll fb[4] = {2, 1, 1, 0}; double next(double p1, double p2, ll ind) { if (ind == 0) return p1 * p2; else if (ind == 1) return (1.0 - p1) * p2; else if (ind == 2) return p1 * (1.0 - p2); // else if(ind==3) return (1.0-p1)*(1.0-p2); else return (1.0 - p1) * (1.0 - p2); } int main(void) { ll n; cin >> n; vector<double> p(n + 1); vector<vector<double>> q(3000, vector<double>(3000, 0.0)); rep1(i, n) { cin >> p[i]; } q[1][0] = p[1]; // round, num o' front q[0][1] = 1.0 - p[1]; for (ll i = 1; i <= n - 2; i += 2) { rep(j, i + 1) { // cout << i-j << "," << j << ":" << endl; rep(k, 4) { // cout << i-j + fb[k] << "," << j + fb[3-k] << endl; // cout << "q:" << q[i-j][j] << "next:" << next(p[i+1],p[i+2],k) << // endl; q[i - j + fb[k]][j + fb[3 - k]] += q[i - j][j] * next(p[i + 1], p[i + 2], k); } } } double ans = 0.0; for (ll i = n; i > n - i; i--) { // cout << i << "," << n-i << endl; ans += q[i][n - i]; } cout << setprecision(20) << ans << endl; return 0; }
[ "io.output.change" ]
977,607
977,608
u242680486
cpp
p03168
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdint> #include <cstdlib> #include <iostream> #include <list> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_r(i, n) for (int i = n - 1; i >= 0; i--) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() #define SZ(x) ((ll)(x).size()) #define bit(n) (1LL << (n)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define INF bit(60) #define pb push_back #define mod 1000000007 template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; using uif = uint_fast64_t; using ll = long long int; int qp(int a, ll b) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mod; a = 1ll * a * a % mod; } while (b >>= 1); return ans; } int qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; ll fb[4] = {2, 1, 1, 0}; double next(double p1, double p2, ll ind) { if (ind == 0) return p1 * p2; else if (ind == 1) return (1.0 - p1) * p2; else if (ind == 2) return p1 * (1.0 - p2); // else if(ind==3) return (1.0-p1)*(1.0-p2); else return (1.0 - p1) * (1.0 - p2); } int main(void) { ll n; cin >> n; vector<double> p(n + 1); vector<vector<double>> q(3000, vector<double>(3000, 0.0)); rep(i, n) { cin >> p[i]; } q[0][0] = 1.0; rep(i, n) q[i + 1][0] = q[i][0] * (1.0 - p[i]); rep(i, n) { rep(j, i + 1) { q[i + 1][j + 1] = q[i][j] * p[i] + q[i][j + 1] * (1.0 - p[i]); } } double ans = 0.0; for (ll i = n; i > n - i; i--) { // cout << i << "," << n-i << endl; ans += q[n][i]; } cout << ans << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <cstdint> #include <cstdlib> #include <iostream> #include <list> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_r(i, n) for (int i = n - 1; i >= 0; i--) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() #define SZ(x) ((ll)(x).size()) #define bit(n) (1LL << (n)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define INF bit(60) #define pb push_back #define mod 1000000007 template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using namespace std; using uif = uint_fast64_t; using ll = long long int; int qp(int a, ll b) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mod; a = 1ll * a * a % mod; } while (b >>= 1); return ans; } int qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; ll fb[4] = {2, 1, 1, 0}; double next(double p1, double p2, ll ind) { if (ind == 0) return p1 * p2; else if (ind == 1) return (1.0 - p1) * p2; else if (ind == 2) return p1 * (1.0 - p2); // else if(ind==3) return (1.0-p1)*(1.0-p2); else return (1.0 - p1) * (1.0 - p2); } int main(void) { ll n; cin >> n; vector<double> p(n + 1); vector<vector<double>> q(3000, vector<double>(3000, 0.0)); rep(i, n) { cin >> p[i]; } q[0][0] = 1.0; rep(i, n) q[i + 1][0] = q[i][0] * (1.0 - p[i]); rep(i, n) { rep(j, i + 1) { q[i + 1][j + 1] = q[i][j] * p[i] + q[i][j + 1] * (1.0 - p[i]); } } double ans = 0.0; for (ll i = n; i > n - i; i--) { // cout << i << "," << n-i << endl; ans += q[n][i]; } cout << setprecision(20) << ans << endl; return 0; }
[ "io.output.change" ]
977,609
977,610
u242680486
cpp
p03168
#include <cstdio> #include <vector> int main() { int n; scanf("%d", &n); std::vector<double> dp(n); dp[0] = 1; for (int i = 0; i < n; ++i) { std::vector<double> g(n); double p; scanf("%lf", &p); for (int j = 0; j <= i; ++j) { g[j] += dp[j] * (1 - p); g[j + 1] += dp[j] * p; } dp.swap(g); } double ret = 0; for (int i = n / 2 + 1; i <= n; ++i) ret += dp[i]; printf("%.10f\n", ret); return 0; }
#include <cstdio> #include <vector> int main() { int n; scanf("%d", &n); std::vector<double> dp(n + 1); dp[0] = 1; for (int i = 0; i < n; ++i) { std::vector<double> g(n + 1); double p; scanf("%lf", &p); for (int j = 0; j <= i; ++j) { g[j] += dp[j] * (1 - p); g[j + 1] += dp[j] * p; } dp.swap(g); } double ret = 0; for (int i = n / 2 + 1; i <= n; ++i) ret += dp[i]; printf("%.10f\n", ret); return 0; }
[ "assignment.change" ]
977,617
977,618
u064708782
cpp
p03168
#include <bits/stdc++.h> #define pb push_back #define ll long long using namespace std; const int MOD = 1000000007; const int nmax = 3123; int n; double p[nmax], ch[nmax], res; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { cin >> p[i]; // scanf("%f",&p[i]); } ch[0] = 1; for (int i = 1; i <= n; ++i) { for (int j = n; j >= 0; --j) { ch[j + 1] += ch[j] * p[i]; ch[j] *= 1 - p[i]; } } for (int j = n / 2 + 1; j <= n; ++j) { res += ch[j]; } cout << res; // printf("%lf",res); return 0; }
#include <bits/stdc++.h> #define pb push_back #define ll long long using namespace std; const int MOD = 1000000007; const int nmax = 3123; int n; double p[nmax], ch[nmax], res; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { cin >> p[i]; // scanf("%f",&p[i]); } ch[0] = 1; for (int i = 1; i <= n; ++i) { for (int j = n; j >= 0; --j) { ch[j + 1] += ch[j] * p[i]; ch[j] *= 1 - p[i]; } } for (int j = n / 2 + 1; j <= n; ++j) { res += ch[j]; } cout << setprecision(9) << res; // printf("%lf",res); return 0; }
[ "io.output.change" ]
977,621
977,622
u787228883
cpp
p03168
#include <bits/stdc++.h> #define MOD 1000000007 using namespace std; typedef long long ll; double dp[3002][3002], p[3002]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> p[i]; dp[0][0] = 1; for (int pos = 1; pos <= n; ++pos) { for (int heads = 0; heads <= pos; ++heads) { dp[pos][heads] += dp[pos - 1][heads - 1] * p[pos]; dp[pos][heads] += dp[pos - 1][heads] * (1 - p[pos]); // cerr << pos << " " << heads << " -> " << dp[pos][heads] << endl; } } double ans = 0; for (int heads = 1; heads <= n; ++heads) if (heads > n - heads) ans += dp[n][heads]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define MOD 1000000007 using namespace std; typedef long long ll; double dp[3002][3002], p[3002]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) cin >> p[i]; dp[0][0] = 1; for (int pos = 1; pos <= n; ++pos) { for (int heads = 0; heads <= pos; ++heads) { dp[pos][heads] += dp[pos - 1][heads - 1] * p[pos]; dp[pos][heads] += dp[pos - 1][heads] * (1 - p[pos]); // cerr << pos << " " << heads << " -> " << dp[pos][heads] << endl; } } double ans = 0; for (int heads = 1; heads <= n; ++heads) if (heads > n - heads) ans += dp[n][heads]; cout << setprecision(10) << ans << endl; return 0; }
[ "io.output.change" ]
977,623
977,624
u810831468
cpp
p03168
/* ---------- STL Libraries ---------- */ // IO library #include <cstdio> #include <fstream> #include <iomanip> #include <ios> #include <iostream> // algorithm library #include <algorithm> #include <cmath> #include <numeric> #include <random> // container library #include <array> #include <bitset> #include <deque> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <unordered_map> #include <vector> /* ---------- Namespace ---------- */ using namespace std; /* ---------- Type ---------- */ using ll = long long; #define int ll #define P pair<ll, ll> /* ---------- Constants */ const ll MOD = 1e9 + 7; const int INF = 1LL << 55; /* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */ signed main() { int N; cin >> N; double p[N]; for (int i = 0; i < N; i++) cin >> p[i]; double dp[N + 1][N + 1]; fill(dp[0], dp[N + 1], 0); dp[0][0] = 1; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i + j >= N) continue; dp[i + 1][j] += dp[i][j] * p[i + j]; dp[i][j + 1] += dp[i][j] * (1 - p[i + j]); } } double ret = 0; for (int j = 0; j <= N; j++) { for (int i = j + 1; i <= N; i++) { if (i + j != N) continue; ret += dp[i][j]; } } cout << ret << endl; return 0; }
/* ---------- STL Libraries ---------- */ // IO library #include <cstdio> #include <fstream> #include <iomanip> #include <ios> #include <iostream> // algorithm library #include <algorithm> #include <cmath> #include <numeric> #include <random> // container library #include <array> #include <bitset> #include <deque> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <unordered_map> #include <vector> /* ---------- Namespace ---------- */ using namespace std; /* ---------- Type ---------- */ using ll = long long; #define int ll #define P pair<ll, ll> /* ---------- Constants */ const ll MOD = 1e9 + 7; const int INF = 1LL << 55; /* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */ signed main() { int N; cin >> N; double p[N]; for (int i = 0; i < N; i++) cin >> p[i]; double dp[N + 1][N + 1]; fill(dp[0], dp[N + 1], 0); dp[0][0] = 1; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (i + j >= N) continue; dp[i + 1][j] += dp[i][j] * p[i + j]; dp[i][j + 1] += dp[i][j] * (1 - p[i + j]); } } double ret = 0; for (int j = 0; j <= N; j++) { for (int i = j + 1; i <= N; i++) { if (i + j != N) continue; ret += dp[i][j]; } } cout << setprecision(10) << ret << endl; return 0; }
[ "io.output.change" ]
977,625
977,626
u853132965
cpp
p03168
#include <iomanip> #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<double> p; p.resize(n + 1); int i, j, k; for (i = 1; i <= n; i++) cin >> p[i]; vector<vector<double>> prob; prob.resize(n + 1); for (i = 0; i <= n; i++) prob[i].resize(n); prob[1][1] = p[1]; prob[1][0] = 1.0 - p[1]; for (i = 2; i <= n; i++) { prob[i][0] = (1.0 - p[i]) * prob[i - 1][0]; for (j = 1; j <= i; j++) { prob[i][j] = prob[i - 1][j] * (1.0 - p[i]) + prob[i - 1][j - 1] * p[i]; } } double ans = 0.0; int lim = (n + 1) / 2; for (i = lim; i <= n; i++) ans = ans + prob[n][i]; cout << setprecision(12) << ans << endl; return 0; }
#include <iomanip> #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<double> p; p.resize(n + 1); int i, j, k; for (i = 1; i <= n; i++) cin >> p[i]; vector<vector<double>> prob; prob.resize(n + 1); for (i = 0; i <= n; i++) prob[i].resize(n + 1); prob[1][1] = p[1]; prob[1][0] = 1.0 - p[1]; for (i = 2; i <= n; i++) { prob[i][0] = (1.0 - p[i]) * prob[i - 1][0]; for (j = 1; j <= i; j++) { prob[i][j] = prob[i - 1][j] * (1.0 - p[i]) + prob[i - 1][j - 1] * p[i]; } } double ans = 0.0; int lim = (n + 1) / 2; for (i = lim; i <= n; i++) ans = ans + prob[n][i]; cout << setprecision(12) << ans << endl; return 0; }
[ "expression.operation.binary.add" ]
977,631
977,632
u491400073
cpp
p03168
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); /// freopen("input.txt", "r", stdin); int n; cin >> n; vector<long double> a(n); for (auto &x : a) cin >> x; const int base = n; vector<vector<long double>> dp(n, vector<long double>(base * 2 + 1)); dp[0][base + 1] = a[0]; dp[0][base - 1] = 1. - a[0]; for (int i = 1; i < n; ++i) { for (int prevBal = -i; prevBal <= i; ++prevBal) { dp[i][prevBal + 1 + base] += dp[i - 1][prevBal + base] * a[i]; dp[i][prevBal - 1 + base] += dp[i - 1][prevBal + base] * a[i]; } } long double ans = 0; for (int bal = 1; bal <= n; ++bal) ans += dp[n - 1][bal + base]; cout << setprecision(10) << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); /// freopen("input.txt", "r", stdin); int n; cin >> n; vector<long double> a(n); for (auto &x : a) cin >> x; const int base = n; vector<vector<long double>> dp(n, vector<long double>(base * 2 + 1)); dp[0][base + 1] = a[0]; dp[0][base - 1] = 1. - a[0]; for (int i = 1; i < n; ++i) { for (int prevBal = -i; prevBal <= i; ++prevBal) { dp[i][prevBal + 1 + base] += dp[i - 1][prevBal + base] * a[i]; dp[i][prevBal - 1 + base] += dp[i - 1][prevBal + base] * (1.0 - a[i]); } } long double ans = 0; for (int bal = 1; bal <= n; ++bal) ans += dp[n - 1][bal + base]; cout << setprecision(10) << ans << '\n'; return 0; }
[]
977,635
977,636
u784576081
cpp
p03168
#include <bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair #define pb push_back #define scanVec(vec, n) \ for (int i = 0; i < n; i++) { \ cin >> vec[i]; \ } #define printVec(vec, n) \ for (int i = 0; i < n; i++) { \ cout << vec[i] << " "; \ } #define S second #define F first const int MOD = 1e9 + 7; const int N = 3005; long double P[N]; long double dp[N][N]; // a d f j k l ; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> P[i]; } cout << endl; dp[0][0] = 1.0; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * P[i]; } for (int i = 1; i <= n; i++) { dp[0][i] = dp[0][i - 1] * (1 - P[i]); } for (int i = 1; i <= n; i++) { for (int j = 1; i + j <= n; j++) { dp[i][j] = dp[i - 1][j] * P[i + j] + dp[i][j - 1] * ((long double)1 - P[i + j]); } } // for(int i = 0; i <= n; i++){ // for(int j = 0; j <= n; j++){ // cout<<dp[i][j]<<" "; // } // cout<<endl; // } double res = 0; for (int i = n / 2 + 1; i <= n; i++) { res += dp[i][n - i]; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define mp make_pair #define pb push_back #define scanVec(vec, n) \ for (int i = 0; i < n; i++) { \ cin >> vec[i]; \ } #define printVec(vec, n) \ for (int i = 0; i < n; i++) { \ cout << vec[i] << " "; \ } #define S second #define F first const int MOD = 1e9 + 7; const int N = 3005; long double P[N]; long double dp[N][N]; // a d f j k l ; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> P[i]; } cout << endl; dp[0][0] = 1.0; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * P[i]; } for (int i = 1; i <= n; i++) { dp[0][i] = dp[0][i - 1] * (1 - P[i]); } for (int i = 1; i <= n; i++) { for (int j = 1; i + j <= n; j++) { dp[i][j] = dp[i - 1][j] * P[i + j] + dp[i][j - 1] * ((long double)1 - P[i + j]); } } // for(int i = 0; i <= n; i++){ // for(int j = 0; j <= n; j++){ // cout<<dp[i][j]<<" "; // } // cout<<endl; // } double res = 0; for (int i = n / 2 + 1; i <= n; i++) { res += dp[i][n - i]; } cout << setprecision(10) << res << endl; return 0; }
[ "io.output.change" ]
977,639
977,640
u319322407
cpp
p03168
#include <bits/stdc++.h> using namespace std; double a[3000]; double f[3000][3000]; int main() { int n, i, j; double ans = 0; scanf("%d", &n); f[0][0] = 1; f[0][1] = 0; for (i = 1; i <= n; i++) { scanf("%llf", &a[i]); f[i][0] = f[i - 1][0] * (1 - a[i]); } for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) { f[i][j] = f[i - 1][j] * (1 - a[i]) + f[i - 1][j - 1] * a[i]; } } for (i = n / 2 + 1; i <= n; i++) ans += f[n][i]; printf("%llf", ans); return 0; }
#include <bits/stdc++.h> using namespace std; double a[3000]; double f[3000][3000]; int main() { int n, i, j; double ans = 0; scanf("%d", &n); f[0][0] = 1; f[0][1] = 0; for (i = 1; i <= n; i++) { scanf("%lf", &a[i]); f[i][0] = f[i - 1][0] * (1 - a[i]); } for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) { f[i][j] = f[i - 1][j] * (1 - a[i]) + f[i - 1][j - 1] * a[i]; } } for (i = n / 2 + 1; i <= n; i++) ans += f[n][i]; printf("%.10lf", ans); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
977,664
977,665
u356929542
cpp
p03168
#include <bits/stdc++.h> using namespace std; using ld = long double; int main() { int n; cin >> n; vector<ld> p(n); for (int i = 0; i < n; i++) cin >> p[i]; vector<vector<ld>> dp(n + 1, vector<ld>(n + 1, 0)); dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < i; j++) { dp[i + 1][j + 1] += dp[i][j] * p[i]; dp[i + 1][j] += dp[i][j] * (1 - p[i]); } } ld res = 0; for (int i = n / 2 + 1; i <= n; i++) { res += dp[n][i]; } cout << setprecision(10) << fixed; cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ld = long double; int main() { int n; cin >> n; vector<ld> p(n); for (int i = 0; i < n; i++) cin >> p[i]; vector<vector<ld>> dp(n + 1, vector<ld>(n + 1, 0)); dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { dp[i + 1][j + 1] += dp[i][j] * p[i]; dp[i + 1][j] += dp[i][j] * (1 - p[i]); } } ld res = 0; for (int i = n / 2 + 1; i <= n; i++) { res += dp[n][i]; } cout << setprecision(10) << fixed; cout << res << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
977,666
977,667
u283229916
cpp
p03168
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define ll long long using namespace std; #define BUF_SIZE 1048576 char _buf[BUF_SIZE], *_is = _buf, *_it = _buf; inline char rdc() { if (_is == _it) _it = (_is = _buf) + fread(_buf, 1, BUF_SIZE, stdin); return *_is++; } inline int rdi() { int x = 0, f = 0; register char ch = rdc(); while ((ch < '0' or ch > '9') and (ch ^ '-')) ch = rdc(); if (ch == '-') f = 1, ch = rdc(); while (ch >= '0' and ch <= '9') x = (x << 3) + (x << 1) + (ch ^ '0'), ch = rdc(); return f ? -x : x; } inline void write(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } inline void _write(int x) { write(x); putchar(' '); } inline void print(int x) { write(x); putchar('\n'); } int n; double p, dp[2][3003], ans; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; int i, j; dp[0][0] = dp[1][0] = 1.0; for (i = 1; i <= n; ++i) { cin >> p; dp[i % 2][0] = (i - p) * dp[(i + 1) % 2][0]; for (j = 1; j <= n; ++j) dp[i % 2][j] = p * dp[(i + 1) % 2][j - 1] + (1 - p) * dp[(i + 1) % 2][j]; } for (i = n / 2 + 1; i <= n; ++i) ans += dp[n % 2][i]; cout << fixed << setprecision(9) << ans << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define ll long long using namespace std; #define BUF_SIZE 1048576 char _buf[BUF_SIZE], *_is = _buf, *_it = _buf; inline char rdc() { if (_is == _it) _it = (_is = _buf) + fread(_buf, 1, BUF_SIZE, stdin); return *_is++; } inline int rdi() { int x = 0, f = 0; register char ch = rdc(); while ((ch < '0' or ch > '9') and (ch ^ '-')) ch = rdc(); if (ch == '-') f = 1, ch = rdc(); while (ch >= '0' and ch <= '9') x = (x << 3) + (x << 1) + (ch ^ '0'), ch = rdc(); return f ? -x : x; } inline void write(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } inline void _write(int x) { write(x); putchar(' '); } inline void print(int x) { write(x); putchar('\n'); } int n; double p, dp[2][3003], ans; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; int i, j; dp[0][0] = dp[1][0] = 1.0; for (i = 1; i <= n; ++i) { cin >> p; dp[i % 2][0] = (1 - p) * dp[(i + 1) % 2][0]; for (j = 1; j <= n; ++j) dp[i % 2][j] = p * dp[(i + 1) % 2][j - 1] + (1 - p) * dp[(i + 1) % 2][j]; } for (i = n / 2 + 1; i <= n; ++i) ans += dp[n % 2][i]; cout << fixed << setprecision(9) << ans << endl; return 0; }
[ "assignment.value.change", "identifier.replace.remove", "literal.replace.add", "expression.operation.binary.change" ]
977,668
977,669
u378667182
cpp
p03168
#include <bits/stdc++.h> using namespace std; #define ll long long #define M 1000000007 double dp[3002][3002]; #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); int main() { IOS; int n; cin >> n; double prob[n + 1]; for (int i = 1; i <= n; i++) cin >> prob[i]; for (int j = 2; j <= n; j++) { dp[1][j] = 0.0; } dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - prob[i]); } dp[1][1] = prob[1]; for (int i = 2; i <= n; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = dp[i - 1][j] * (1 - prob[i]) + dp[i - 1][j - 1] * (prob[i]); } } /*for(int i=0;i<=n;i++) { for(int j=0;j<=n;j++) { cout<<dp[i][j]<<" "; } cout<<endl; }*/ double ans = 0; for (int j = n / 2 + 1; j <= n; j++) { ans += dp[n][j]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define M 1000000007 double dp[3002][3002]; #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); int main() { IOS; int n; cin >> n; double prob[n + 1]; for (int i = 1; i <= n; i++) cin >> prob[i]; for (int j = 2; j <= n; j++) { dp[1][j] = 0.0; } dp[0][0] = 1; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - prob[i]); } dp[1][1] = prob[1]; for (int i = 2; i <= n; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = dp[i - 1][j] * (1 - prob[i]) + dp[i - 1][j - 1] * (prob[i]); } } /*for(int i=0;i<=n;i++) { for(int j=0;j<=n;j++) { cout<<dp[i][j]<<" "; } cout<<endl; }*/ double ans = 0; for (int j = n / 2 + 1; j <= n; j++) { ans += dp[n][j]; } cout << setprecision(10) << ans << endl; return 0; }
[ "io.output.change" ]
977,670
977,671
u834901453
cpp
p03168
#include <bits/stdc++.h> using namespace std; using ll = long long; #define forx(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) for (int i = 0; i < (n); i++) int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; double p; double dp[n + 1][n + 1] = {0}; dp[0][0] = 1; rep(i, n) { cin >> p; rep(j, i + 1) { dp[i + 1][j + 1] += dp[i][j] * p; dp[i + 1][j] += dp[i][j] * (1 - p); } } double ans = 0; forx(i, (n + 1) / 2, n + 1) ans += dp[n][i]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define forx(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) for (int i = 0; i < (n); i++) int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; double p; double dp[n + 1][n + 1] = {0}; dp[0][0] = 1; rep(i, n) { cin >> p; rep(j, i + 1) { dp[i + 1][j + 1] += dp[i][j] * p; dp[i + 1][j] += dp[i][j] * (1 - p); } } double ans = 0; forx(i, (n + 1) / 2, n + 1) ans += dp[n][i]; cout << setprecision(12) << ans << endl; return 0; }
[ "io.output.change" ]
977,706
977,707
u604231488
cpp
p03168
#include "bits/stdc++.h" #define Rep(i, n) for (int i = 0; i < n; i++) #define For(i, n1, n2) for (int i = n1; i < n2; i++) #define REP(i, n) for (ll i = 0; i < n; i++) #define FOR(i, n1, n2) for (ll i = n1; i < n2; i++) #define put(a) cout << a << endl; #define all(a) (a).begin(), (a).end() #define SORT(c) sort((c).begin(), (c).end()) #define TDARRAY(int, a, n, m) vector<vector<int>> a(n, vector<int>(m, 0)); using namespace std; typedef long long ll; typedef pair<int, int> P; int n; int main() { cin >> n; vector<double> p(n); REP(i, n) { cin >> p[i]; } // vector<vector<double>> dp(n+1,vector<double>(n,0)); TDARRAY(double, dp, n + 1, n + 1); dp[0][0] = (double)1; REP(i, n) { REP(j, n) { dp[i + 1][j + 1] += dp[i][j] * p[i]; dp[i + 1][j] += dp[i][j] * (1 - p[i]); } } double res = 0; FOR(j, n / 2 + 1, n) { res += dp[n][j]; } cout << setprecision(10) << res << endl; return 0; }
#include "bits/stdc++.h" #define Rep(i, n) for (int i = 0; i < n; i++) #define For(i, n1, n2) for (int i = n1; i < n2; i++) #define REP(i, n) for (ll i = 0; i < n; i++) #define FOR(i, n1, n2) for (ll i = n1; i < n2; i++) #define put(a) cout << a << endl; #define all(a) (a).begin(), (a).end() #define SORT(c) sort((c).begin(), (c).end()) #define TDARRAY(int, a, n, m) vector<vector<int>> a(n, vector<int>(m, 0)); using namespace std; typedef long long ll; typedef pair<int, int> P; int n; int main() { cin >> n; vector<double> p(n); REP(i, n) { cin >> p[i]; } TDARRAY(double, dp, n + 1, n + 1); dp[0][0] = (double)1; REP(i, n) { REP(j, n) { dp[i + 1][j + 1] += dp[i][j] * p[i]; dp[i + 1][j] += dp[i][j] * (1 - p[i]); } } double res = 0; FOR(j, n / 2 + 1, n + 1) { res += dp[n][j]; } cout << setprecision(10) << res << endl; return 0; }
[ "expression.operation.binary.add" ]
977,722
977,723
u030685402
cpp
p03168
#include <bits/stdc++.h> using namespace std; float a[3001], f[3001][3001]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } f[1][1] = a[1]; f[1][0] = (double)(1 - a[1]); for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { f[i][j] = f[i - 1][j] * (1.0 - a[i]) + f[i - 1][j - 1] * a[i]; } } float ans = 0.0; for (int i = (n + 1) / 2; i <= n; i++) { ans += f[n][i]; } printf("%.9f", ans); }
#include <bits/stdc++.h> using namespace std; double a[3001], f[3001][3001]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } f[1][1] = a[1]; f[1][0] = (double)(1 - a[1]); for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { f[i][j] = f[i - 1][j] * (1.0 - a[i]) + f[i - 1][j - 1] * a[i]; } } double ans = 0.0; for (int i = (n + 1) / 2; i <= n; i++) { ans += f[n][i]; } printf("%.9f", ans); }
[ "variable_declaration.type.primitive.change" ]
977,747
977,748
u201455094
cpp
p03168
#include <bits/stdc++.h> #define ll long long #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define all(a) (a).begin(), (a).end() #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define sz size #define fr first #define sc second #define pb push_back #define er erase #define in insert #define mp make_pair #define pi pair #define rc(s) return cout << s, 0 #define int long long using namespace std; int n; double p[3000]; double dp[3000][3000][3]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(0); cout.tie(0); cout << fixed << setprecision(25); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; dp[1][1][1] = p[1]; dp[1][0][0] = (1 - p[1]); for (int i = 2; i <= n; i++) { for (int j = 1; j <= i; j++) { dp[i][j][1] = (dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1]) * p[i]; dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) * (1 - p[i]); } } int j = n / 2 + 1; double ans = 0; for (int i = j; i <= n; i++) { ans += (dp[n][i][1] + dp[n][i][0]); } cout << ans; }
#include <bits/stdc++.h> #define ll long long #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define all(a) (a).begin(), (a).end() #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define sz size #define fr first #define sc second #define pb push_back #define er erase #define in insert #define mp make_pair #define pi pair #define rc(s) return cout << s, 0 #define int long long using namespace std; int n; double p[3000]; double dp[3000][3000][3]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(0); cout.tie(0); cout << fixed << setprecision(10); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; dp[1][1][1] = p[1]; dp[1][0][0] = (1 - p[1]); for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { dp[i][j][1] = (dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1]) * p[i]; dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) * (1 - p[i]); } } int j = n / 2 + 1; double ans = 0; for (int i = j; i <= n; i++) { ans += (dp[n][i][1] + dp[n][i][0]); } cout << ans; }
[ "literal.number.change", "io.output.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
977,753
977,754
u022510862
cpp
p03168
#include <bits/stdc++.h> #define ll long long #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define all(a) (a).begin(), (a).end() #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define sz size #define fr first #define sc second #define pb push_back #define er erase #define in insert #define mp make_pair #define pi pair #define rc(s) return cout << s, 0 #define int long long using namespace std; int n; double p[3000]; double dp[3000][3000][3]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(0); cout.tie(0); cout << fixed << setprecision(25); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; dp[1][1][1] = p[1]; dp[1][0][0] = (1 - p[1]); for (int i = 2; i <= n; i++) { for (int j = 1; j <= i; j++) { dp[i][j][1] = (dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1]) * p[i]; dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) * (1 - p[i]); } } int j = n / 2 + 1; double ans = 0; for (int i = j; i <= n; i++) { ans += (dp[n][i][1] + dp[n][i][0]); } cout << ans; }
#include <bits/stdc++.h> #define ll long long #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define all(a) (a).begin(), (a).end() #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define sz size #define fr first #define sc second #define pb push_back #define er erase #define in insert #define mp make_pair #define pi pair #define rc(s) return cout << s, 0 #define int long long using namespace std; int n; double p[3000]; double dp[3000][3000][3]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(0); cout.tie(0); cout << fixed << setprecision(10); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; dp[1][1][1] = p[1]; dp[1][0][0] = (1 - p[1]); for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { dp[i][j][1] = (dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1]) * p[i]; dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) * (1 - p[i]); } } int j = n / 2 + 1; double ans = 0; for (int i = j; i <= n; i++) { ans += (dp[n][i][1] + dp[n][i][0]); } cout << ans; }
[ "literal.number.change", "io.output.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
977,755
977,754
u022510862
cpp
p03168
#include <bits/stdc++.h> #define ll long long #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define all(a) (a).begin(), (a).end() #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define sz size #define fr first #define sc second #define pb push_back #define er erase #define in insert #define mp make_pair #define pi pair #define rc(s) return cout << s, 0 #define int long long using namespace std; int n; double p[3000]; double dp[3000][3000][3]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(0); cout.tie(0); cout << fixed << setprecision(14); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; dp[1][1][1] = p[1]; dp[1][0][0] = (1 - p[1]); for (int i = 2; i <= n; i++) { for (int j = 1; j <= i; j++) { dp[i][j][1] = (dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1]) * p[i]; dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) * (1 - p[i]); } } int j = n / 2 + 1; double ans = 0; for (int i = j; i <= n; i++) { ans += (dp[n][i][1] + dp[n][i][0]); } cout << ans; }
#include <bits/stdc++.h> #define ll long long #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define all(a) (a).begin(), (a).end() #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define sz size #define fr first #define sc second #define pb push_back #define er erase #define in insert #define mp make_pair #define pi pair #define rc(s) return cout << s, 0 #define int long long using namespace std; int n; double p[3000]; double dp[3000][3000][3]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(0); cout.tie(0); cout << fixed << setprecision(10); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; dp[1][1][1] = p[1]; dp[1][0][0] = (1 - p[1]); for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { dp[i][j][1] = (dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1]) * p[i]; dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) * (1 - p[i]); } } int j = n / 2 + 1; double ans = 0; for (int i = j; i <= n; i++) { ans += (dp[n][i][1] + dp[n][i][0]); } cout << ans; }
[ "literal.number.change", "io.output.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
977,756
977,754
u022510862
cpp
p03168
#include <bits/stdc++.h> #define ll long long #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define all(a) (a).begin(), (a).end() #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define sz size #define fr first #define sc second #define pb push_back #define er erase #define in insert #define mp make_pair #define pi pair #define rc(s) return cout << s, 0 #define int long long using namespace std; int n; double p[3000]; double dp[3000][3000][3]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(0); cout.tie(0); cout << fixed << setprecision(7); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; dp[1][1][1] = p[1]; dp[1][0][0] = (1 - p[1]); for (int i = 2; i <= n; i++) { for (int j = 1; j <= i; j++) { dp[i][j][1] = (dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1]) * p[i]; dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) * (1 - p[i]); } } int j = n / 2 + 1; double ans = 0; for (int i = j; i <= n; i++) { ans += (dp[n][i][1] + dp[n][i][0]); } cout << ans; }
#include <bits/stdc++.h> #define ll long long #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define all(a) (a).begin(), (a).end() #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define sz size #define fr first #define sc second #define pb push_back #define er erase #define in insert #define mp make_pair #define pi pair #define rc(s) return cout << s, 0 #define int long long using namespace std; int n; double p[3000]; double dp[3000][3000][3]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cerr.tie(0); cout.tie(0); cout << fixed << setprecision(10); cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; dp[1][1][1] = p[1]; dp[1][0][0] = (1 - p[1]); for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { dp[i][j][1] = (dp[i - 1][j - 1][0] + dp[i - 1][j - 1][1]) * p[i]; dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) * (1 - p[i]); } } int j = n / 2 + 1; double ans = 0; for (int i = j; i <= n; i++) { ans += (dp[n][i][1] + dp[n][i][0]); } cout << ans; }
[ "literal.number.change", "io.output.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
977,757
977,754
u022510862
cpp
p03168
#include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; #define REP(i, n) for (long long i = 0; i < (n); i++) #define FOR(i, m, n) for (long long i = (m); i < (n); ++i) #define ALL(obj) (obj).begin(), (obj).end() template <class T> using V = vector<T>; template <class T, class U> using P = pair<T, U>; const ll MOD = (ll)1e9 + 7; const ll HINF = (ll)1e18; const ll LINF = (ll)1e9; const long double PI = 3.1415926535897932384626433; template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } } template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; } template <class T> ostream &operator<<(ostream &o, const set<T> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; } template <template <class tmp> class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } void print(void) { cout << endl; } template <class Head> void print(Head &&head) { cout << head; print(); } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { cout << head << " "; print(forward<Tail>(tail)...); } void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; } void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; } void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; } int main() { int N; cin >> N; V<long double> p(N + 1, 0); FOR(i, 1, N + 1) cin >> p[i]; V<V<long double>> dp(N + 1, V<long double>(N + 1, 0.)); dp[0][0] = 1.; FOR(i, 1, N + 1) { REP(j, N + 1) { if (j > i) continue; dp[i][j] += dp[i - 1][j] * (1. - p[i]); dp[i][j] += dp[i - 1][j - 1] * p[i]; } } long double ans = 0.; REP(i, N + 1) if (i > N / 2) ans += dp[N][i]; printf("%.12f/n", ans); return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; #define REP(i, n) for (long long i = 0; i < (n); i++) #define FOR(i, m, n) for (long long i = (m); i < (n); ++i) #define ALL(obj) (obj).begin(), (obj).end() template <class T> using V = vector<T>; template <class T, class U> using P = pair<T, U>; const ll MOD = (ll)1e9 + 7; const ll HINF = (ll)1e18; const ll LINF = (ll)1e9; const long double PI = 3.1415926535897932384626433; template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } } template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; } template <class T> ostream &operator<<(ostream &o, const set<T> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; } template <template <class tmp> class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } void print(void) { cout << endl; } template <class Head> void print(Head &&head) { cout << head; print(); } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { cout << head << " "; print(forward<Tail>(tail)...); } void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; } void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; } void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; } int main() { int N; cin >> N; V<double> p(N + 1, 0); FOR(i, 1, N + 1) cin >> p[i]; V<V<double>> dp(N + 1, V<double>(N + 1, 0.)); dp[0][0] = 1.; FOR(i, 1, N + 1) { REP(j, N + 1) { if (j > i) continue; dp[i][j] += dp[i - 1][j] * (1. - p[i]); dp[i][j] += dp[i - 1][j - 1] * p[i]; } } double ans = 0.; REP(i, N + 1) if (i > N / 2) ans += dp[N][i]; printf("%.12f", ans); return 0; }
[ "variable_declaration.type.narrow.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
977,764
977,765
u898651494
cpp
p03168
#include <bits/stdc++.h> using namespace std; using int64 = long long; const int64 INF = 1LL << 59; const int mod = 1e9 + 7; int N; double P[3000]; double dp[6002][3000]; bool memo[6002][3000]; double rec(int up, int idx) { if (idx == N) return up > 3000 ? 1.0 : 0.0; if (exchange(memo[up][idx], true)) return dp[up][idx]; double ret = 0.0; ret += rec(up + 1, idx + 1) * P[idx]; ret += rec(up - 1, idx + 1) * (1 - P[idx]); return dp[up][idx] = ret; } int main() { cin >> N; for (int i = 0; i < N; i++) cin >> P[i]; cout << fixed << setprecision(10) << rec(2000, 0) << endl; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; const int64 INF = 1LL << 59; const int mod = 1e9 + 7; int N; double P[3000]; double dp[6002][3000]; bool memo[6002][3000]; double rec(int up, int idx) { if (idx == N) return up > 3000 ? 1.0 : 0.0; if (exchange(memo[up][idx], true)) return dp[up][idx]; double ret = 0.0; ret += rec(up + 1, idx + 1) * P[idx]; ret += rec(up - 1, idx + 1) * (1 - P[idx]); return dp[up][idx] = ret; } int main() { cin >> N; for (int i = 0; i < N; i++) cin >> P[i]; cout << fixed << setprecision(10) << rec(3000, 0) << endl; }
[ "literal.number.change", "io.output.change" ]
977,767
977,768
u524343822
cpp
p03168
#include <bits/stdc++.h> using namespace std; const int N = 3e3 + 5; int n; double dp[N][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; dp[0][0] = 1; for (int i = 1; i <= n; ++i) { double p; cin >> p; for (int j = 0; j <= i; ++j) { int k = i - j; if (j) dp[j][k] += dp[j - 1][k] * p; if (k) dp[j][k] += dp[j][k - 1] * p; } } double ans = 0; for (int i = 0; i <= n; ++i) if (n - i < i) ans += dp[i][n - i]; cout << fixed << setprecision(10) << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 3e3 + 5; int n; double dp[N][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; dp[0][0] = 1; for (int i = 1; i <= n; ++i) { double p; cin >> p; for (int j = 0; j <= i; ++j) { int k = i - j; if (j) dp[j][k] += dp[j - 1][k] * p; if (k) dp[j][k] += dp[j][k - 1] * (1 - p); } } double ans = 0; for (int i = 0; i <= n; ++i) if (n - i < i) ans += dp[i][n - i]; cout << fixed << setprecision(10) << ans; return 0; }
[]
977,776
977,777
u760290068
cpp
p03168
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 3e3 + 7; long double p[N], f[N][N]; int main() { int n; long double ans = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%Lf", &p[i]); } f[1][1] = p[1]; f[1][0] = 1 - p[1]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { f[i][j] = f[i - 1][j] * (1 - p[i]); if (j - 1 >= 0) { f[i][j] += f[i - 1][j - 1] * p[i]; } } } for (int i = n; i > n - i; i--) { ans += f[n][i]; } printf(".12%Lf\n", ans); return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 3e3 + 7; long double p[N], f[N][N]; int main() { int n; long double ans = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%Lf", &p[i]); } f[1][1] = p[1]; f[1][0] = 1 - p[1]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= i; j++) { f[i][j] = f[i - 1][j] * (1 - p[i]); if (j - 1 >= 0) { f[i][j] += f[i - 1][j - 1] * p[i]; } } } for (int i = n; i > n - i; i--) { ans += f[n][i]; } printf("%.12Lf\n", ans); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
977,789
977,790
u171891488
cpp
p03168
#include <bits/stdc++.h> using namespace std; #define scd(t) scanf("%d", &t) #define scld(t) scanf("%ld", &t) #define sclld(t) scanf("%lld", &t) #define scc(t) scanf("%c", &t) #define scs(t) scanf("%s", t) #define scf(t) scanf("%f", &t) #define sclf(t) scanf("%lf", &t) #define MEM(a, b) memset(a, (b), sizeof(a)) #define ffor(i, j, k, in) for (int i = j; i < k; i += in) #define rfor(i, j, k, in) for (int i = j; i >= k; i -= in) #define rep(i, j) ffor(i, 0, j, 1) #define rrep(i, j) rfor(i, j, 0, 1) #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert(B <= A && A <= C) #define mp make_pair #define pb push_back //#define f first //#define s second #define inf (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 #define read(type) readInt<type>() #define trace1(x) cout << #x << ": " << x << endl; #define trace2(x, y) \ cout << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; const double pi = acos(-1.0); typedef pair<long long int, long long int> pii; typedef long long ll; typedef vector<long long int> vi; typedef vector<string> vs; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef map<long long int, long long int> mpii; typedef set<long long int> sei; typedef multiset<long long int> msei; typedef long int int32; typedef unsigned long int uint32; typedef long long int int64; typedef unsigned long long int uint64; int main() { ios::sync_with_stdio(0); cin.tie(NULL); ll i, j, n, m; cin >> n; long double a[n + 1]; for (i = 1; i <= n; i++) { cin >> a[i]; } long double dp[n + 1][n + 1]; for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) dp[i][j] = 0.0; } dp[0][0] = 1; for (i = 1; i <= n; i++) { for (j = i; j >= 1; j--) { dp[i][j] = dp[i - 1][j - 1] * a[i] + dp[i - 1][j] * ((long double)1 - a[i]); } dp[i][0] = dp[i - 1][0] * ((long double)1 - a[i]); } long double cnt = 0; for (i = n / 2 + 1; i <= n; i++) cnt += dp[n][i]; cout << cnt; return 0; }
#include <bits/stdc++.h> using namespace std; #define scd(t) scanf("%d", &t) #define scld(t) scanf("%ld", &t) #define sclld(t) scanf("%lld", &t) #define scc(t) scanf("%c", &t) #define scs(t) scanf("%s", t) #define scf(t) scanf("%f", &t) #define sclf(t) scanf("%lf", &t) #define MEM(a, b) memset(a, (b), sizeof(a)) #define ffor(i, j, k, in) for (int i = j; i < k; i += in) #define rfor(i, j, k, in) for (int i = j; i >= k; i -= in) #define rep(i, j) ffor(i, 0, j, 1) #define rrep(i, j) rfor(i, j, 0, 1) #define all(cont) cont.begin(), cont.end() #define rall(cont) cont.end(), cont.begin() #define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++) #define IN(A, B, C) assert(B <= A && A <= C) #define mp make_pair #define pb push_back //#define f first //#define s second #define inf (int)1e9 #define EPS 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 #define read(type) readInt<type>() #define trace1(x) cout << #x << ": " << x << endl; #define trace2(x, y) \ cout << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; const double pi = acos(-1.0); typedef pair<long long int, long long int> pii; typedef long long ll; typedef vector<long long int> vi; typedef vector<string> vs; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef map<long long int, long long int> mpii; typedef set<long long int> sei; typedef multiset<long long int> msei; typedef long int int32; typedef unsigned long int uint32; typedef long long int int64; typedef unsigned long long int uint64; int main() { ios::sync_with_stdio(0); cin.tie(NULL); ll i, j, n, m; cin >> n; long double a[n + 1]; for (i = 1; i <= n; i++) { cin >> a[i]; } long double dp[n + 1][n + 1]; for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) dp[i][j] = 0.0; } dp[0][0] = 1; for (i = 1; i <= n; i++) { for (j = i; j >= 1; j--) { dp[i][j] = dp[i - 1][j - 1] * a[i] + dp[i - 1][j] * ((long double)1 - a[i]); } dp[i][0] = dp[i - 1][0] * ((long double)1 - a[i]); } long double cnt = 0; for (i = n / 2 + 1; i <= n; i++) cnt += dp[n][i]; cout << setprecision(15) << cnt; return 0; }
[ "io.output.change" ]
977,801
977,802
u696401314
cpp
p03169
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) double sol(int i, int j, int k, vector<vector<vector<double>>> &dp) { if (dp[i][j][k] or i + j + k == 0) return dp[i][j][k]; int N = dp.size() - 1; dp[i][j][k] += N / (i + j + k); if (i > 0) dp[i][j][k] += sol(i - 1, j, k, dp) * i / (i + j + k); if (j > 0) dp[i][j][k] += sol(i + 1, j - 1, k, dp) * j / (i + j + k); if (k > 0) dp[i][j][k] += sol(i, j + 1, k - 1, dp) * k / (i + j + k); return dp[i][j][k]; } int main() { int N; cin >> N; vector<int> a(N); REP(i, N) cin >> a[i]; vector<vector<vector<double>>> dp( N + 1, vector<vector<double>>(N + 1, vector<double>(N + 1, 0))); cout << fixed << setprecision(10) << sol(count(a.begin(), a.end(), 1), count(a.begin(), a.end(), 2), count(a.begin(), a.end(), 3), dp) << endl; return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) double sol(int i, int j, int k, vector<vector<vector<double>>> &dp) { if (dp[i][j][k] or i + j + k == 0) return dp[i][j][k]; int N = dp.size() - 1; dp[i][j][k] += (double)N / (i + j + k); if (i > 0) dp[i][j][k] += sol(i - 1, j, k, dp) * i / (i + j + k); if (j > 0) dp[i][j][k] += sol(i + 1, j - 1, k, dp) * j / (i + j + k); if (k > 0) dp[i][j][k] += sol(i, j + 1, k - 1, dp) * k / (i + j + k); return dp[i][j][k]; } int main() { int N; cin >> N; vector<int> a(N); REP(i, N) cin >> a[i]; vector<vector<vector<double>>> dp( N + 1, vector<vector<double>>(N + 1, vector<double>(N + 1, 0))); cout << fixed << setprecision(10) << sol(count(a.begin(), a.end(), 1), count(a.begin(), a.end(), 2), count(a.begin(), a.end(), 3), dp) << endl; return 0; }
[ "type_conversion.add" ]
977,817
977,818
u127285813
cpp
p03169
#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> VI; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; #define rep(a, n) for (ll a = 0; a < n; a++) #define repi(a, b, n) for (ll a = b; a < n; a++) #include <bits/stdc++.h> using namespace std; constexpr ll INF = 1e15; constexpr ll mod = 1e9 + 7; template <typename T> void cmpmax(T &reference, T value) { reference = max(reference, value); } template <typename T> void cmpmin(T &reference, T value) { reference = min(reference, value); } int main() { int n; cin >> n; vector<int> as(n); vector<int> counts(4, 0); rep(i, n) { cin >> as[i]; counts[as[i]]++; } vector<vector<vector<double>>> dp( n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1, -1))); // dp[i][j][k]...1枚の皿がi個、2枚の皿がj個、3枚の皿がk個のときに、必要な手数の期待値 // dp[i][j][k] = (n-i-j-k) / n * dp[i][j][k] + i / n * dp[i-1][j][k] + j / n * // dp[i+1][j-1][k] + k / n * dp[i][j+1][k-1] + 1 (i+j+k)/n * dp[i][j][k] = i / //n * dp[i-1][j][k] + j / n * dp[i+1][j-1][k] + k / n * dp[i][j+1][k-1] + 1 dp[0][0][0] = 0; const double dn = n; rep(k, counts[3] + 1) { rep(j, n + 1) { rep(i, n + 1) { if (i == 0 && j == 0 && k == 0) continue; double right = 1; if (i > 0) right += i * dp[i - 1][j][k]; if (j > 0 && i < n) right += j * dp[i + 1][j - 1][k]; if (k > 0 && j < n) right += k * dp[i][j + 1][k - 1]; right *= 1.0 / (i + j + k); dp[i][j][k] = right; } } } cout << setprecision(10) << dp[counts[1]][counts[2]][counts[3]] << endl; return 0; }
#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> VI; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; #define rep(a, n) for (ll a = 0; a < n; a++) #define repi(a, b, n) for (ll a = b; a < n; a++) #include <bits/stdc++.h> using namespace std; constexpr ll INF = 1e15; constexpr ll mod = 1e9 + 7; template <typename T> void cmpmax(T &reference, T value) { reference = max(reference, value); } template <typename T> void cmpmin(T &reference, T value) { reference = min(reference, value); } int main() { int n; cin >> n; vector<int> as(n); vector<int> counts(4, 0); rep(i, n) { cin >> as[i]; counts[as[i]]++; } vector<vector<vector<double>>> dp( n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1, -1))); // dp[i][j][k]...1枚の皿がi個、2枚の皿がj個、3枚の皿がk個のときに、必要な手数の期待値 // dp[i][j][k] = (n-i-j-k) / n * dp[i][j][k] + i / n * dp[i-1][j][k] + j / n * // dp[i+1][j-1][k] + k / n * dp[i][j+1][k-1] + 1 (i+j+k)/n * dp[i][j][k] = i / //n * dp[i-1][j][k] + j / n * dp[i+1][j-1][k] + k / n * dp[i][j+1][k-1] + 1 dp[0][0][0] = 0; const double dn = n; rep(k, counts[3] + 1) { rep(j, n + 1) { rep(i, n + 1) { if (i == 0 && j == 0 && k == 0) continue; double right = dn; if (i > 0) right += i * dp[i - 1][j][k]; if (j > 0 && i < n) right += j * dp[i + 1][j - 1][k]; if (k > 0 && j < n) right += k * dp[i][j + 1][k - 1]; right *= 1.0 / (i + j + k); dp[i][j][k] = right; } } } cout << setprecision(10) << dp[counts[1]][counts[2]][counts[3]] << endl; return 0; }
[ "variable_declaration.value.change", "identifier.replace.add", "literal.replace.remove" ]
977,819
977,820
u834771741
cpp
p03169
#include <bits/stdc++.h> using namespace std; #define int long long #define nn 301 #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) int n; int x = 0, y = 0, z = 0; double dp[nn][nn][nn]; double solve(int x, int y, int z) { if (x < 0 || y < 0 || z < 0) return 0; if (x == 0 && y == 0 && z == 0) return 0; if (dp[x][y][z] > -0.9) return dp[x][y][z]; double exp = n + x * solve(x - 1, y, z) + y * solve(x + 1, y - 1, z) + z * solve(x, y + 1, z - 1); return dp[x][y][z] = exp / (x + y + z); } int32_t main() { FAST; cin >> n; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) { int val; cin >> val; if (val == 1) x++; else if (val == 2) y++; else z++; } cout << fixed << setprecision(10); cout << solve(x, y, z); }
#include <bits/stdc++.h> using namespace std; #define int long long #define nn 301 #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) int n; int x = 0, y = 0, z = 0; double dp[nn][nn][nn]; double solve(int x, int y, int z) { if (x < 0 || y < 0 || z < 0) return 0; if (x == 0 && y == 0 && z == 0) return 0; if (dp[x][y][z] > -0.9) return dp[x][y][z]; double exp = n + x * solve(x - 1, y, z) + y * solve(x + 1, y - 1, z) + z * solve(x, y + 1, z - 1); return dp[x][y][z] = exp / (x + y + z); } int32_t main() { FAST; cin >> n; memset(dp, -1, sizeof(dp)); for (int i = 1; i <= n; i++) { int val; cin >> val; if (val == 1) x++; else if (val == 2) y++; else z++; } cout << fixed << setprecision(10); cout << solve(x, y, z); }
[ "literal.number.change", "call.arguments.change" ]
977,821
977,822
u093748998
cpp
p03169
#include <bits/stdc++.h> using namespace std; #define int long long #define nn 301 #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) int n; int x = 0, y = 0, z = 0; double dp[nn][nn][nn]; double solve(int x, int y, int z) { if (x < 0 || y < 0 || z < 0) return 0; if (x == 0 && y == 0 && z == 0) return 0; if (dp[x][y][z] > -0.9) return dp[x][y][z]; double exp = n + x * solve(x - 1, y, z) + y * solve(x + 1, y - 1, z) + z * solve(x, y + 1, z - 1); return dp[x][y][z] = exp / (x + y + z); } int32_t main() { FAST; cin >> n; memset(dp, 0, sizeof(dp)); for (int i = 1; i < -n; i++) { int val; cin >> val; if (val == 1) x++; else if (val == 2) y++; else z++; } cout << fixed << setprecision(10); cout << solve(x, y, z); }
#include <bits/stdc++.h> using namespace std; #define int long long #define nn 301 #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) int n; int x = 0, y = 0, z = 0; double dp[nn][nn][nn]; double solve(int x, int y, int z) { if (x < 0 || y < 0 || z < 0) return 0; if (x == 0 && y == 0 && z == 0) return 0; if (dp[x][y][z] > -0.9) return dp[x][y][z]; double exp = n + x * solve(x - 1, y, z) + y * solve(x + 1, y - 1, z) + z * solve(x, y + 1, z - 1); return dp[x][y][z] = exp / (x + y + z); } int32_t main() { FAST; cin >> n; memset(dp, -1, sizeof(dp)); for (int i = 1; i <= n; i++) { int val; cin >> val; if (val == 1) x++; else if (val == 2) y++; else z++; } cout << fixed << setprecision(10); cout << solve(x, y, z); }
[ "literal.number.change", "call.arguments.change", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change", "expression.operation.unary.arithmetic.remove" ]
977,823
977,822
u093748998
cpp
p03169
#include <bits/stdc++.h> using namespace std; #define d double const int sz = 301; d dp[301][301][301]; d solve(int one, int two, int three, int n) { if (one == 0 and two == 0 and three == 0) return 0; if (one < 0 or two < 0 or three < 0) return 0.0; if (dp[one][two][three] > -0.9) return dp[one][two][three]; int ans = n + one * solve(one - 1, two, three, n) + two * solve(one + 1, two - 1, three, n) + three * solve(one, two + 1, three - 1, n); return dp[one][two][three] = (ans / (one + two + three)); } int main() { for (int i = 0; i < 301; i++) { for (int j = 0; j < 301; ++j) { for (int k = 0; k < 301; ++k) { dp[i][j][k] = -1; } } } int n = 0; cin >> n; int one = 0, two = 0, three = 0; int temp = 0; for (int i = 1; i <= n; ++i) { cin >> temp; if (temp == 1) one++; if (temp == 2) two++; if (temp == 3) three++; } cout << fixed << setprecision(10) << solve(one, two, three, n) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define d double const int sz = 301; d dp[301][301][301]; d solve(int one, int two, int three, int n) { if (one == 0 and two == 0 and three == 0) return 0; if (one < 0 or two < 0 or three < 0) return 0.0; if (dp[one][two][three] > -0.9) return dp[one][two][three]; d ans = n + one * solve(one - 1, two, three, n) + two * solve(one + 1, two - 1, three, n) + three * solve(one, two + 1, three - 1, n); return dp[one][two][three] = (ans / (one + two + three)); } int main() { for (int i = 0; i < 301; i++) { for (int j = 0; j < 301; ++j) { for (int k = 0; k < 301; ++k) { dp[i][j][k] = -1; } } } int n = 0; cin >> n; int one = 0, two = 0, three = 0; int temp = 0; for (int i = 1; i <= n; ++i) { cin >> temp; if (temp == 1) one++; if (temp == 2) two++; if (temp == 3) three++; } cout << fixed << setprecision(10) << solve(one, two, three, n) << endl; return 0; }
[]
977,828
977,829
u579458117
cpp
p03169
#include <bits/stdc++.h> #define int long long int using namespace std; const int N = 320; int n, a, b[3]; long double d[N], dp[N][N][N]; int32_t main() { cout << setprecision(20) << fixed; cin >> n; for (int i = 0; i < n; i++) { cin >> a; b[a - 1]++; } for (int i = 0; i <= n; i++) { int h = 100; d[i] = 1; while (h--) { d[i] = 1 + (long double)(i * d[i]) / n; } } for (int k = 0; k <= n; k++) { for (int j = 0; j <= n - k; j++) { for (int i = 0; i <= n - k - j; i++) { if (i + j + k == 0) continue; long double dd; dp[i][j][k] = d[n - i - j - k]; if (i) { dd = i; // dd /= n ; dd /= i + j + k; dp[i][j][k] += dd * dp[i - 1][j][k]; } if (j) { dd = j; // dd /= n ; dd /= i + j + k; dp[i][j][k] += dd * dp[i + 1][j - 1][k]; } if (k) { dd = k; /// dd /= n; dd /= i + j + k; dp[i][j][k] += dd * dp[i][j + 1][k - 1]; } } } } /*for(int i = 0 ; i <= n ; i++){ for(int j = 0 ; j <= n ; j++){ for(int k = 0 ; k <= n; k++){ cout << dp[i][j][k] << " "; } cout << '\n'; } for(int j = 0 ; j < n + 5 ; j++){ cout << '\n' ; } }*/ cout << dp[b[0]][b[1]][b[2]]; return 0; } /* #include <radman/roderc++.h> ....._____ .~~~~~////////\\ ... .:::::////////////\\ ....::////////.. (/\\\\... .:::::////// \\\\///\\ .::::// ..:::::///////////////. \\\\\$$$$$$ \\\\\////// \\\\///\\ //\\\////// \\\\\////////////////////. ""\\$$$$$$$ \\\\\//// \\\\//// |||||////////. \\\\\///// ~~~~~////// ... "\$$$$ \\\\\//\ ////|||/ \\\\\///////// \\\\\//\ ~~~~~////// (/\\\\... . \\\\\//\ ////|||/ |||||////*\\///. \\\\\//\ ~~~~~////// \\\\\$$$$$$ .@@@@@. \\\\\//\ ////|||/ \\\\\///|\\\//// \\\\\//\ ~~~~~////// ""\\$$$$$$$ @@@@////\ \\\\\//\ ____---/|||/ |||||///|\\\\\///. \\\\\//\ ~~~~~////// "\$$$$ @@@@\///\ \\\\\//\--|||||||_-' \\\\\///|\\\\\//// \\\\\//\ ~~~~~////// ,@@@@|///| \\\\\//\|||||_"-\\\\\ |||||///| ~~~~~///. \\\\\//\ ~~~~~////// .@@@@. /@@@@@|///// \\\\\//\///"""\\\\\\\\ \\\\\///|~~~~[[[////. \\\\\//\ ~~~~~////// @@@@@@@@ ..@@@@@.////// \\\\\//\ \"""\\\\\\\ |||||///|~~[[[[["\////. \\\\\//\ ~~~~~////// '@@@@/////\ .:;@@@@@@@..///////" \\\\\//\ \"""\\\\\\ \\\\\///|[[[[*\\\\\////. \\\\\//\ ~~~~~////// *@@@\//////\@@@@@@@@..//////////" \\\\\//\ \:::\\\\/ |||||///|[[[* \\\\\\/// \\\\\//\~~~~~///////' *@@\/////////////////////" \\\\\//\ \___\\/ \\\\\///|* \\\\\/" \\\\\//\~~////////' **"///////////""" \\\\\//\ |||||///| \\\\\//\///////" \\\\\//\ \\\\\///| \\\\\//\////" \\\\\/// |||||////| \\\\\////" \\\\\/" \\\\\///* \\\\\/" """""* */
#include <bits/stdc++.h> #define int long long int using namespace std; const int N = 320; int n, a, b[3]; long double d[N], dp[N][N][N]; int32_t main() { cout << setprecision(20) << fixed; cin >> n; for (int i = 0; i < n; i++) { cin >> a; b[a - 1]++; } for (int i = 0; i <= n; i++) { int h = 100000; d[i] = 1; while (h--) { d[i] = 1 + (long double)(i * d[i]) / n; } } for (int k = 0; k <= n; k++) { for (int j = 0; j <= n - k; j++) { for (int i = 0; i <= n - k - j; i++) { if (i + j + k == 0) continue; long double dd; dp[i][j][k] = d[n - i - j - k]; if (i) { dd = i; // dd /= n ; dd /= i + j + k; dp[i][j][k] += dd * dp[i - 1][j][k]; } if (j) { dd = j; // dd /= n ; dd /= i + j + k; dp[i][j][k] += dd * dp[i + 1][j - 1][k]; } if (k) { dd = k; /// dd /= n; dd /= i + j + k; dp[i][j][k] += dd * dp[i][j + 1][k - 1]; } } } } /*for(int i = 0 ; i <= n ; i++){ for(int j = 0 ; j <= n ; j++){ for(int k = 0 ; k <= n; k++){ cout << dp[i][j][k] << " "; } cout << '\n'; } for(int j = 0 ; j < n + 5 ; j++){ cout << '\n' ; } }*/ cout << dp[b[0]][b[1]][b[2]]; return 0; } /* #include <radman/roderc++.h> ....._____ .~~~~~////////\\ ... .:::::////////////\\ ....::////////.. (/\\\\... .:::::////// \\\\///\\ .::::// ..:::::///////////////. \\\\\$$$$$$ \\\\\////// \\\\///\\ //\\\////// \\\\\////////////////////. ""\\$$$$$$$ \\\\\//// \\\\//// |||||////////. \\\\\///// ~~~~~////// ... "\$$$$ \\\\\//\ ////|||/ \\\\\///////// \\\\\//\ ~~~~~////// (/\\\\... . \\\\\//\ ////|||/ |||||////*\\///. \\\\\//\ ~~~~~////// \\\\\$$$$$$ .@@@@@. \\\\\//\ ////|||/ \\\\\///|\\\//// \\\\\//\ ~~~~~////// ""\\$$$$$$$ @@@@////\ \\\\\//\ ____---/|||/ |||||///|\\\\\///. \\\\\//\ ~~~~~////// "\$$$$ @@@@\///\ \\\\\//\--|||||||_-' \\\\\///|\\\\\//// \\\\\//\ ~~~~~////// ,@@@@|///| \\\\\//\|||||_"-\\\\\ |||||///| ~~~~~///. \\\\\//\ ~~~~~////// .@@@@. /@@@@@|///// \\\\\//\///"""\\\\\\\\ \\\\\///|~~~~[[[////. \\\\\//\ ~~~~~////// @@@@@@@@ ..@@@@@.////// \\\\\//\ \"""\\\\\\\ |||||///|~~[[[[["\////. \\\\\//\ ~~~~~////// '@@@@/////\ .:;@@@@@@@..///////" \\\\\//\ \"""\\\\\\ \\\\\///|[[[[*\\\\\////. \\\\\//\ ~~~~~////// *@@@\//////\@@@@@@@@..//////////" \\\\\//\ \:::\\\\/ |||||///|[[[* \\\\\\/// \\\\\//\~~~~~///////' *@@\/////////////////////" \\\\\//\ \___\\/ \\\\\///|* \\\\\/" \\\\\//\~~////////' **"///////////""" \\\\\//\ |||||///| \\\\\//\///////" \\\\\//\ \\\\\///| \\\\\//\////" \\\\\/// |||||////| \\\\\////" \\\\\/" \\\\\///* \\\\\/" """""* */
[ "literal.number.change", "variable_declaration.value.change" ]
977,834
977,835
u917609891
cpp
p03169
#include <bits/stdc++.h> #define ll long long int using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) double dp[303][303][303] = {}; double dfs(int i, int j, int k, int n) { // if(dp[i][j][k]!=-1) return dp[i][j][k]; if ((i < 0) || (j < 0) || (k < 0)) return 0; else if ((i == 0) && (j == 0) && (k == 0)) return dp[i][j][k] = 0; else if (dp[i][j][k] != -1) return dp[i][j][k]; return dp[i][j][k] = ((double)n / (i + j + k)) + ((((double)i) / (i + j + k) * (dfs(i - 1, j, k, n))) + (((double)j) / (i + j + k) * (dfs(i + 1, j - 1, k, n))) + (((double)k) / (i + j + k) * (dfs(i, j + 1, k - 1, n)))); return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); // MEM(dp,-1); for (int i = 0; i <= 303; i++) for (int j = 0; j < 303; j++) for (int k = 0; k < 303; k++) dp[i][j][k] = -1; int i, n; cin >> n; int a = 0, b = 0, c = 0, z = 0, count[4] = {}; for (i = 0; i < n; i++) { cin >> z; if (z == 1) a++; if (z == 2) b++; if (z == 3) c++; } double ans = dfs(a, b, c, n); cout << fixed << setprecision(12) << ans; }
#include <bits/stdc++.h> #define ll long long int using namespace std; #define MEM(a, b) memset(a, (b), sizeof(a)) double dp[303][303][303] = {}; double dfs(int i, int j, int k, int n) { // if(dp[i][j][k]!=-1) return dp[i][j][k]; if ((i < 0) || (j < 0) || (k < 0)) return 0; else if ((i == 0) && (j == 0) && (k == 0)) return dp[i][j][k] = 0; else if (dp[i][j][k] != -1) return dp[i][j][k]; return dp[i][j][k] = ((double)n / (i + j + k)) + ((((double)i) / (i + j + k) * (dfs(i - 1, j, k, n))) + (((double)j) / (i + j + k) * (dfs(i + 1, j - 1, k, n))) + (((double)k) / (i + j + k) * (dfs(i, j + 1, k - 1, n)))); return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); // MEM(dp,-1); for (int i = 0; i < 303; i++) for (int j = 0; j < 303; j++) for (int k = 0; k < 303; k++) dp[i][j][k] = -1; int i, n; cin >> n; int a = 0, b = 0, c = 0, z = 0, count[4] = {}; for (i = 0; i < n; i++) { cin >> z; if (z == 1) a++; if (z == 2) b++; if (z == 3) c++; } double ans = dfs(a, b, c, n); cout << fixed << setprecision(12) << ans; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
977,839
977,840
u863091189
cpp
p03169
/***************************************** START OF TEMPLATE * *********************************************/ #include <bits/stdc++.h> using namespace std; #define SPEED \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); \ cout << fixed; \ cout << setprecision(16); #define randomINIT \ mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define foo(i, a, n) for (ll i = (a); i <= n; i++) #define frr(i, a, n) for (ll i = (a); i >= n; i--) #define fo(i, n) for (ll i = 0; i < n; i++) #define newl cout << "\n"; #define f first #define s second #define pb push_back #define mp make_pair #define sym(s) s = "#" + s + "#"; #define all(x) (x).begin(), (x).end() #define alll(x, n) x + 1, x + n + 1 #define ll long long #define ld long double #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> const ld PI = 3.14159265358979323846; const ll MOD = 1e+9 + 7; const ll INF = LLONG_MAX; const int INFi = INT_MAX; const ll N = 3e+2 + 8; void _print() { cout << ""; } void __print(int x) { cout << x; } void __print(long long x) { cout << x; } void __print(float x) { cout << x; } void __print(double x) { cout << x; } void __print(long double x) { cout << x; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(char x) { cout << '\'' << x << '\''; } void __print(const string &x) { cout << '\"' << x << '\"'; } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? ", " : ""), __print(i); cout << "}"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } template <typename T1, typename T2> void mset(T1 &x, T2 val) { memset(x, val, sizeof(x)); } template <typename T1, typename T2> void mset(T1 &a, ll n, T2 v) { foo(i, 0, n) a[i] = v; } template <typename T1, typename T2> void mset(T1 &a, ll n, ll m, T2 v) { foo(i, 0, n) foo(j, 0, m) a[i][j] = v; } template <typename T1> void OUT(T1 a[], ll n, ll m) { foo(i, 1, n) { foo(j, 1, m) { cout << a[i][j] << " "; } newl; } } void OUT(ll a[], ll n) { foo(i, 1, n) cout << a[i] << " "; newl; } void OUT(pll a[], ll n) { foo(i, 1, n) __print(a[i]); newl; } #define debug(x...) \ _print(x); \ newl; vll adj[N]; ll vis[N]; ll dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; ll test_cases = 1; randomINIT; /*********************************************************************************************************/ /***************************************** VARIABLE DECLARATIONS * *****************************************/ ll n, x; ld dp[N][N][N]; /***************************************** FUNCTION IMPLEMENTATIONS * **************************************/ ld solve(ll f1, ll f2, ll f3) { if (f1 == 0 && f2 == 0 && f3 == 0) return 0; if (f1 < 0 || f2 < 0 || f3 < 0) return 0; if (dp[f1][f2][f3] != -1) return dp[f1][f2][f3]; ll k = f1 + f2 + f3; ld ans = n + f1 * solve(f1 - 1, f2, f3) + f2 * solve(f1 + 1, f2 - 1, f3) + f3 * solve(f1, f2 + 1, f3 - 1); ans /= k; return dp[f1][f2][f3] = ans; } /***************************************** START OF MAIN FUNCTION * ****************************************/ void MAIN(ll tc) { mset(dp, -1); ll c1 = 0, c2 = 0, c3 = 0; cin >> n; foo(i, 1, n) { cin >> x; if (x == 1) c1++; else if (x == 2) c2++; else c3++; } cout << solve(c1, c2, c3); } int main() { SPEED; // cin>>test_cases; foo(i, 1, test_cases) { MAIN(i); } }
/***************************************** START OF TEMPLATE * *********************************************/ #include <bits/stdc++.h> using namespace std; #define SPEED \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); \ cout << fixed; \ cout << setprecision(15); #define randomINIT \ mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define foo(i, a, n) for (ll i = (a); i <= n; i++) #define frr(i, a, n) for (ll i = (a); i >= n; i--) #define fo(i, n) for (ll i = 0; i < n; i++) #define newl cout << "\n"; #define f first #define s second #define pb push_back #define mp make_pair #define sym(s) s = "#" + s + "#"; #define all(x) (x).begin(), (x).end() #define alll(x, n) x + 1, x + n + 1 #define ll long long #define ld double #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> const ld PI = 3.14159265358979323846; const ll MOD = 1e+9 + 7; const ll INF = LLONG_MAX; const int INFi = INT_MAX; const ll N = 3e+2 + 8; void _print() { cout << ""; } void __print(int x) { cout << x; } void __print(long long x) { cout << x; } void __print(float x) { cout << x; } void __print(double x) { cout << x; } void __print(long double x) { cout << x; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(char x) { cout << '\'' << x << '\''; } void __print(const string &x) { cout << '\"' << x << '\"'; } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? ", " : ""), __print(i); cout << "}"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } template <typename T1, typename T2> void mset(T1 &x, T2 val) { memset(x, val, sizeof(x)); } template <typename T1, typename T2> void mset(T1 &a, ll n, T2 v) { foo(i, 0, n) a[i] = v; } template <typename T1, typename T2> void mset(T1 &a, ll n, ll m, T2 v) { foo(i, 0, n) foo(j, 0, m) a[i][j] = v; } template <typename T1> void OUT(T1 a[], ll n, ll m) { foo(i, 1, n) { foo(j, 1, m) { cout << a[i][j] << " "; } newl; } } void OUT(ll a[], ll n) { foo(i, 1, n) cout << a[i] << " "; newl; } void OUT(pll a[], ll n) { foo(i, 1, n) __print(a[i]); newl; } #define debug(x...) \ _print(x); \ newl; vll adj[N]; ll vis[N]; ll dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; ll test_cases = 1; randomINIT; /*********************************************************************************************************/ /***************************************** VARIABLE DECLARATIONS * *****************************************/ ll n, x; ld dp[N][N][N]; /***************************************** FUNCTION IMPLEMENTATIONS * **************************************/ ld solve(ll f1, ll f2, ll f3) { if (f1 < 0 || f2 < 0 || f3 < 0) return 0; if (f1 == 0 && f2 == 0 && f3 == 0) return 0; if (dp[f1][f2][f3] > 0) return dp[f1][f2][f3]; ld ans = n + f1 * solve(f1 - 1, f2, f3) + f2 * solve(f1 + 1, f2 - 1, f3) + f3 * solve(f1, f2 + 1, f3 - 1); return dp[f1][f2][f3] = ans / (f1 + f2 + f3); } /***************************************** START OF MAIN FUNCTION * ****************************************/ void MAIN(ll tc) { ll c1 = 0, c2 = 0, c3 = 0; cin >> n; foo(i, 1, n) { cin >> x; if (x == 1) c1++; else if (x == 2) c2++; else c3++; } mset(dp, -1); cout << solve(c1, c2, c3); } int main() { SPEED; // cin>>test_cases; foo(i, 1, test_cases) { MAIN(i); } }
[ "preprocessor.define.value.change", "literal.integer.change" ]
977,843
977,844
u622748505
cpp
p03169
/***************************************** START OF TEMPLATE * *********************************************/ #include <bits/stdc++.h> using namespace std; #define SPEED \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); \ cout << fixed; \ cout << setprecision(16); #define randomINIT \ mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define foo(i, a, n) for (ll i = (a); i <= n; i++) #define frr(i, a, n) for (ll i = (a); i >= n; i--) #define fo(i, n) for (ll i = 0; i < n; i++) #define newl cout << "\n"; #define f first #define s second #define pb push_back #define mp make_pair #define sym(s) s = "#" + s + "#"; #define all(x) (x).begin(), (x).end() #define alll(x, n) x + 1, x + n + 1 #define ll long long #define ld long double #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> const ld PI = 3.14159265358979323846; const ll MOD = 1e+9 + 7; const ll INF = LLONG_MAX; const int INFi = INT_MAX; const ll N = 3e+2 + 8; void _print() { cout << ""; } void __print(int x) { cout << x; } void __print(long long x) { cout << x; } void __print(float x) { cout << x; } void __print(double x) { cout << x; } void __print(long double x) { cout << x; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(char x) { cout << '\'' << x << '\''; } void __print(const string &x) { cout << '\"' << x << '\"'; } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? ", " : ""), __print(i); cout << "}"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } template <typename T1, typename T2> void mset(T1 &x, T2 val) { memset(x, val, sizeof(x)); } template <typename T1, typename T2> void mset(T1 &a, ll n, T2 v) { foo(i, 0, n) a[i] = v; } template <typename T1, typename T2> void mset(T1 &a, ll n, ll m, T2 v) { foo(i, 0, n) foo(j, 0, m) a[i][j] = v; } template <typename T1> void OUT(T1 a[], ll n, ll m) { foo(i, 1, n) { foo(j, 1, m) { cout << a[i][j] << " "; } newl; } } void OUT(ll a[], ll n) { foo(i, 1, n) cout << a[i] << " "; newl; } void OUT(pll a[], ll n) { foo(i, 1, n) __print(a[i]); newl; } #define debug(x...) \ _print(x); \ newl; vll adj[N]; ll vis[N]; ll dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; ll test_cases = 1; randomINIT; /*********************************************************************************************************/ /***************************************** VARIABLE DECLARATIONS * *****************************************/ ll n, x; ld dp[N][N][N]; /***************************************** FUNCTION IMPLEMENTATIONS * **************************************/ ld solve(ll f1, ll f2, ll f3) { if (f1 == 0 && f2 == 0 && f3 == 0) return 0; if (f1 < 0 || f2 < 0 || f3 < 0) return 0; if (dp[f1][f2][f3] != -1) return dp[f1][f2][f3]; ld ans = 0; ld k = f1 + f2 + f3; ld p1 = f1 / k; ld p2 = f2 / k; ld p3 = f3 / k; ans = n / k + p1 * solve(f1 - 1, f2, f3) + p2 * solve(f1 + 1, f2 - 1, f3) + p3 * solve(f1, f2 + 1, f3 - 1); return dp[f1][f2][f3] = ans; } /***************************************** START OF MAIN FUNCTION * ****************************************/ void MAIN(ll tc) { mset(dp, -1); ll c1 = 0, c2 = 0, c3 = 0; cin >> n; foo(i, 1, n) { cin >> x; if (x == 1) c1++; else if (x == 2) c2++; else c3++; } cout << solve(c1, c2, c3); } int main() { SPEED; // cin>>test_cases; foo(i, 1, test_cases) { MAIN(i); } }
/***************************************** START OF TEMPLATE * *********************************************/ #include <bits/stdc++.h> using namespace std; #define SPEED \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); \ cout << fixed; \ cout << setprecision(15); #define randomINIT \ mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define foo(i, a, n) for (ll i = (a); i <= n; i++) #define frr(i, a, n) for (ll i = (a); i >= n; i--) #define fo(i, n) for (ll i = 0; i < n; i++) #define newl cout << "\n"; #define f first #define s second #define pb push_back #define mp make_pair #define sym(s) s = "#" + s + "#"; #define all(x) (x).begin(), (x).end() #define alll(x, n) x + 1, x + n + 1 #define ll long long #define ld double #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> const ld PI = 3.14159265358979323846; const ll MOD = 1e+9 + 7; const ll INF = LLONG_MAX; const int INFi = INT_MAX; const ll N = 3e+2 + 8; void _print() { cout << ""; } void __print(int x) { cout << x; } void __print(long long x) { cout << x; } void __print(float x) { cout << x; } void __print(double x) { cout << x; } void __print(long double x) { cout << x; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(char x) { cout << '\'' << x << '\''; } void __print(const string &x) { cout << '\"' << x << '\"'; } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? ", " : ""), __print(i); cout << "}"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } template <typename T1, typename T2> void mset(T1 &x, T2 val) { memset(x, val, sizeof(x)); } template <typename T1, typename T2> void mset(T1 &a, ll n, T2 v) { foo(i, 0, n) a[i] = v; } template <typename T1, typename T2> void mset(T1 &a, ll n, ll m, T2 v) { foo(i, 0, n) foo(j, 0, m) a[i][j] = v; } template <typename T1> void OUT(T1 a[], ll n, ll m) { foo(i, 1, n) { foo(j, 1, m) { cout << a[i][j] << " "; } newl; } } void OUT(ll a[], ll n) { foo(i, 1, n) cout << a[i] << " "; newl; } void OUT(pll a[], ll n) { foo(i, 1, n) __print(a[i]); newl; } #define debug(x...) \ _print(x); \ newl; vll adj[N]; ll vis[N]; ll dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; ll test_cases = 1; randomINIT; /*********************************************************************************************************/ /***************************************** VARIABLE DECLARATIONS * *****************************************/ ll n, x; ld dp[N][N][N]; /***************************************** FUNCTION IMPLEMENTATIONS * **************************************/ ld solve(ll f1, ll f2, ll f3) { if (f1 < 0 || f2 < 0 || f3 < 0) return 0; if (f1 == 0 && f2 == 0 && f3 == 0) return 0; if (dp[f1][f2][f3] > 0) return dp[f1][f2][f3]; ld ans = n + f1 * solve(f1 - 1, f2, f3) + f2 * solve(f1 + 1, f2 - 1, f3) + f3 * solve(f1, f2 + 1, f3 - 1); return dp[f1][f2][f3] = ans / (f1 + f2 + f3); } /***************************************** START OF MAIN FUNCTION * ****************************************/ void MAIN(ll tc) { ll c1 = 0, c2 = 0, c3 = 0; cin >> n; foo(i, 1, n) { cin >> x; if (x == 1) c1++; else if (x == 2) c2++; else c3++; } mset(dp, -1); cout << solve(c1, c2, c3); } int main() { SPEED; // cin>>test_cases; foo(i, 1, test_cases) { MAIN(i); } }
[ "preprocessor.define.value.change", "literal.integer.change" ]
977,845
977,844
u622748505
cpp
p03169
/***************************************** START OF TEMPLATE * *********************************************/ #include <bits/stdc++.h> using namespace std; #define SPEED \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); \ cout << fixed; \ cout << setprecision(10); #define randomINIT \ mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define foo(i, a, n) for (ll i = (a); i <= n; i++) #define frr(i, a, n) for (ll i = (a); i >= n; i--) #define fo(i, n) for (ll i = 0; i < n; i++) #define newl cout << "\n"; #define f first #define s second #define pb push_back #define mp make_pair #define sym(s) s = "#" + s + "#"; #define all(x) (x).begin(), (x).end() #define alll(x, n) x + 1, x + n + 1 #define ll long long #define ld long double #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> const ld PI = 3.14159265358979323846; const ll MOD = 1e+9 + 7; const ll INF = LLONG_MAX; const int INFi = INT_MAX; const ll N = 3e+2 + 8; void _print() { cout << ""; } void __print(int x) { cout << x; } void __print(long long x) { cout << x; } void __print(float x) { cout << x; } void __print(double x) { cout << x; } void __print(long double x) { cout << x; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(char x) { cout << '\'' << x << '\''; } void __print(const string &x) { cout << '\"' << x << '\"'; } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? ", " : ""), __print(i); cout << "}"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } template <typename T1, typename T2> void mset(T1 &x, T2 val) { memset(x, val, sizeof(x)); } template <typename T1, typename T2> void mset(T1 &a, ll n, T2 v) { foo(i, 0, n) a[i] = v; } template <typename T1, typename T2> void mset(T1 &a, ll n, ll m, T2 v) { foo(i, 0, n) foo(j, 0, m) a[i][j] = v; } template <typename T1> void OUT(T1 a[], ll n, ll m) { foo(i, 1, n) { foo(j, 1, m) { cout << a[i][j] << " "; } newl; } } void OUT(ll a[], ll n) { foo(i, 1, n) cout << a[i] << " "; newl; } void OUT(pll a[], ll n) { foo(i, 1, n) __print(a[i]); newl; } #define debug(x...) \ _print(x); \ newl; vll adj[N]; ll vis[N]; ll dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; ll test_cases = 1; randomINIT; /*********************************************************************************************************/ /***************************************** VARIABLE DECLARATIONS * *****************************************/ ll n, x; ld dp[N][N][N]; /***************************************** FUNCTION IMPLEMENTATIONS * **************************************/ ld solve(ll f1, ll f2, ll f3) { if (f1 == 0 && f2 == 0 && f3 == 0) return 0; if (f1 < 0 || f2 < 0 || f3 < 0) return 0; if (dp[f1][f2][f3] != -1) return dp[f1][f2][f3]; ld ans = 0; ld k = f1 + f2 + f3; ld p1 = f1 / k; ld p2 = f2 / k; ld p3 = f3 / k; ans = n / k + p1 * solve(f1 - 1, f2, f3) + p2 * solve(f1 + 1, f2 - 1, f3) + p3 * solve(f1, f2 + 1, f3 - 1); return dp[f1][f2][f3] = ans; } /***************************************** START OF MAIN FUNCTION * ****************************************/ void MAIN(ll tc) { mset(dp, -1); ll c1 = 0, c2 = 0, c3 = 0; cin >> n; foo(i, 1, n) { cin >> x; if (x == 1) c1++; else if (x == 2) c2++; else c3++; } cout << solve(c1, c2, c3); } int main() { SPEED; // cin>>test_cases; foo(i, 1, test_cases) { MAIN(i); } }
/***************************************** START OF TEMPLATE * *********************************************/ #include <bits/stdc++.h> using namespace std; #define SPEED \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); \ cout << fixed; \ cout << setprecision(15); #define randomINIT \ mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); #define foo(i, a, n) for (ll i = (a); i <= n; i++) #define frr(i, a, n) for (ll i = (a); i >= n; i--) #define fo(i, n) for (ll i = 0; i < n; i++) #define newl cout << "\n"; #define f first #define s second #define pb push_back #define mp make_pair #define sym(s) s = "#" + s + "#"; #define all(x) (x).begin(), (x).end() #define alll(x, n) x + 1, x + n + 1 #define ll long long #define ld double #define pll pair<ll, ll> #define vll vector<ll> #define vpll vector<pll> const ld PI = 3.14159265358979323846; const ll MOD = 1e+9 + 7; const ll INF = LLONG_MAX; const int INFi = INT_MAX; const ll N = 3e+2 + 8; void _print() { cout << ""; } void __print(int x) { cout << x; } void __print(long long x) { cout << x; } void __print(float x) { cout << x; } void __print(double x) { cout << x; } void __print(long double x) { cout << x; } void __print(const char *x) { cout << '\"' << x << '\"'; } void __print(char x) { cout << '\'' << x << '\''; } void __print(const string &x) { cout << '\"' << x << '\"'; } template <typename T, typename V> void __print(const pair<T, V> &x) { cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}'; } template <typename T> void __print(const T &x) { int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? ", " : ""), __print(i); cout << "}"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cout << ", "; _print(v...); } template <typename T1, typename T2> void mset(T1 &x, T2 val) { memset(x, val, sizeof(x)); } template <typename T1, typename T2> void mset(T1 &a, ll n, T2 v) { foo(i, 0, n) a[i] = v; } template <typename T1, typename T2> void mset(T1 &a, ll n, ll m, T2 v) { foo(i, 0, n) foo(j, 0, m) a[i][j] = v; } template <typename T1> void OUT(T1 a[], ll n, ll m) { foo(i, 1, n) { foo(j, 1, m) { cout << a[i][j] << " "; } newl; } } void OUT(ll a[], ll n) { foo(i, 1, n) cout << a[i] << " "; newl; } void OUT(pll a[], ll n) { foo(i, 1, n) __print(a[i]); newl; } #define debug(x...) \ _print(x); \ newl; vll adj[N]; ll vis[N]; ll dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; ll test_cases = 1; randomINIT; /*********************************************************************************************************/ /***************************************** VARIABLE DECLARATIONS * *****************************************/ ll n, x; ld dp[N][N][N]; /***************************************** FUNCTION IMPLEMENTATIONS * **************************************/ ld solve(ll f1, ll f2, ll f3) { if (f1 < 0 || f2 < 0 || f3 < 0) return 0; if (f1 == 0 && f2 == 0 && f3 == 0) return 0; if (dp[f1][f2][f3] > 0) return dp[f1][f2][f3]; ld ans = n + f1 * solve(f1 - 1, f2, f3) + f2 * solve(f1 + 1, f2 - 1, f3) + f3 * solve(f1, f2 + 1, f3 - 1); return dp[f1][f2][f3] = ans / (f1 + f2 + f3); } /***************************************** START OF MAIN FUNCTION * ****************************************/ void MAIN(ll tc) { ll c1 = 0, c2 = 0, c3 = 0; cin >> n; foo(i, 1, n) { cin >> x; if (x == 1) c1++; else if (x == 2) c2++; else c3++; } mset(dp, -1); cout << solve(c1, c2, c3); } int main() { SPEED; // cin>>test_cases; foo(i, 1, test_cases) { MAIN(i); } }
[ "preprocessor.define.value.change", "literal.integer.change" ]
977,846
977,844
u622748505
cpp
p03169
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; typedef pair<ll, ll> pll; const ll mod = 1e9 + 7; // const ll mod=998244353; const ll inf = 5e18; vector<vector<vector<double>>> dp(301, vector<vector<double>>(301, vector<double>(301, -1))); ll n; double res(ll n1, ll n2, ll n3) { if (dp[n1][n2][n3] > -1) return dp[n1][n2][n3]; else { dp[n1][n2][n3] = double(n); if (n3 > 0) { dp[n1][n2][n3] += res(n1, n2 + 1, n3 - 1) * n3; } if (n2 > 0) { dp[n1][n2][n3] += res(n1 + 1, n2 - 1, n3) * n2; } if (n1 > 0) { dp[n1][n2][n3] += res(n1 - 1, n2, n3) * n1; } dp[n1][n2][n3] *= 1.0 / (n1 + n2 + n3); return dp[n1][n2][n3]; } } int main() { dp[0][0][0] = -1.0; cin >> n; vec num(3, 0); for (ll i = 0; i < n; i++) { ll tmp; cin >> tmp; num[tmp - 1]++; } cout << fixed << setprecision(10) << res(num[0], num[1], num[2]) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; typedef pair<ll, ll> pll; const ll mod = 1e9 + 7; // const ll mod=998244353; const ll inf = 5e18; vector<vector<vector<double>>> dp(301, vector<vector<double>>(301, vector<double>(301, -1))); ll n; double res(ll n1, ll n2, ll n3) { if (dp[n1][n2][n3] > -1) return dp[n1][n2][n3]; else { dp[n1][n2][n3] = double(n); if (n3 > 0) { dp[n1][n2][n3] += res(n1, n2 + 1, n3 - 1) * n3; } if (n2 > 0) { dp[n1][n2][n3] += res(n1 + 1, n2 - 1, n3) * n2; } if (n1 > 0) { dp[n1][n2][n3] += res(n1 - 1, n2, n3) * n1; } dp[n1][n2][n3] *= 1.0 / (n1 + n2 + n3); return dp[n1][n2][n3]; } } int main() { dp[0][0][0] = 0.0; cin >> n; vec num(3, 0); for (ll i = 0; i < n; i++) { ll tmp; cin >> tmp; num[tmp - 1]++; } cout << fixed << setprecision(10) << res(num[0], num[1], num[2]) << endl; }
[ "literal.number.change", "assignment.value.change" ]
977,849
977,850
u718758485
cpp
p03169
// atCoder - Sushi #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <vector> using namespace std; #define fill(a, val) memset(a, val, sizeof(a)) #define ll long long int double dp[302][302][302]; ll n; double solve(int s1, int s2, int s3) { if (s1 < 0 || s2 < 0 || s3 < 0) return 0; if (s1 == 0 && s2 == 0 && s3 == 0) return 0; if (dp[s1][s2][s3] > -0.9) return dp[s1][s2][s3]; dp[s1][s2][s3] = n + s1 * solve(s1 - 1, s2, s3) + s2 * solve(s1 + 1, s2 - 1, s3) + s3 * solve(s1, s2 + 1, s3 - 1); dp[s1][s2][s3] = dp[s1][s2][s3] / s1 + s2 + s3; return dp[s1][s2][s3]; } int main() { cin >> n; int s1 = 0, s2 = 0, s3 = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) { s1++; } else if (a == 2) { s2++; } else if (a == 3) { s3++; } } fill(dp, -1); cout << fixed << setprecision(10) << solve(s1, s2, s3); return 0; }
// atCoder - Sushi #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <vector> using namespace std; #define fill(a, val) memset(a, val, sizeof(a)) #define ll long long int double dp[302][302][302]; ll n; double solve(int s1, int s2, int s3) { if (s1 < 0 || s2 < 0 || s3 < 0) return 0; if (s1 == 0 && s2 == 0 && s3 == 0) return 0; if (dp[s1][s2][s3] > -0.9) return dp[s1][s2][s3]; dp[s1][s2][s3] = n + s1 * solve(s1 - 1, s2, s3) + s2 * solve(s1 + 1, s2 - 1, s3) + s3 * solve(s1, s2 + 1, s3 - 1); dp[s1][s2][s3] = dp[s1][s2][s3] / (s1 + s2 + s3); return dp[s1][s2][s3]; } int main() { cin >> n; int s1 = 0, s2 = 0, s3 = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) { s1++; } else if (a == 2) { s2++; } else if (a == 3) { s3++; } } fill(dp, -1); cout << fixed << setprecision(8) << solve(s1, s2, s3); return 0; }
[ "literal.number.change", "io.output.change" ]
977,851
977,852
u048224524
cpp
p03169
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1000000007 using namespace std; int n; double dp[310][310][310]; double rec(int i, int j, int k) { if (dp[i][j][k] >= 0) return dp[i][j][k]; if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; if (i > 0) res += rec(i - 1, j, k) * i; if (j > 0) res += rec(i + 1, j - 1, k) * j; if (k > 0) res += rec(i, j + 1, k - 1) * k; res += n; res *= 1.0 / (i + j + k); return dp[i][j][k] = res; } int main() { cin >> n; int a[n]; int one = 0, two = 0, three = 0; rep(i, n) { cin >> a[i]; if (a[i] == 1) one++; else if (a[i] == 2) two++; else three++; } // memset(dp,-1,sizeof(dp)); rep(i, n) rep(j, n) rep(k, n) dp[i][j][k] = -1; cout << fixed << setprecision(10) << rec(one, two, three) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1000000007 using namespace std; int n; double dp[310][310][310]; double rec(int i, int j, int k) { if (dp[i][j][k] >= 0) return dp[i][j][k]; if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; if (i > 0) res += rec(i - 1, j, k) * i; if (j > 0) res += rec(i + 1, j - 1, k) * j; if (k > 0) res += rec(i, j + 1, k - 1) * k; res += n; res *= 1.0 / (i + j + k); return dp[i][j][k] = res; } int main() { cin >> n; int a[n]; int one = 0, two = 0, three = 0; rep(i, n) { cin >> a[i]; if (a[i] == 1) one++; else if (a[i] == 2) two++; else three++; } // memset(dp,-1,sizeof(dp)); rep(i, n + 1) rep(j, n + 1) rep(k, n + 1) dp[i][j][k] = -1; // cout << fixed << setprecision(10) << rec(one, two, three) << endl; return 0; }
[ "assignment.change" ]
977,853
977,854
u110006361
cpp
p03169
//{{{ #include <bits/stdc++.h> using namespace std; #define putchar(x) cout << (x) #define repeat(x) \ int _ = 0; \ _ < (x); \ ++_ template <typename T> constexpr auto range(T start, T stop, T step) { struct iterator { T i, step; bool operator!=(const iterator &other) const { return i != other.i; } auto &operator++() { i += step; return *this; } auto &operator*() { return i; } }; struct iterable_wrapper { T start, stop, step; auto begin() const { return iterator{start, step}; } auto end() const { return iterator{stop, step}; } size_t size() const { return (stop - start) / step; } iterable_wrapper(T start_, T stop_, T step_) : start(start_), stop(stop_), step(step_) { stop = step > 0 ? max(start, stop) : min(start, stop); stop += (step - (stop - start) % step) % step; } }; return iterable_wrapper(start, stop, step); }; template <typename T> constexpr auto range(T start, T stop) { return range(start, stop, T(1)); } template <typename T> constexpr auto range(T stop) { return range(T(0), stop, T(1)); } template <typename T, typename Iter = decltype(begin(declval<T>()))> constexpr auto printer(T &&iterable) { struct iterator { Iter iter, ed; auto operator!=(const iterator &other) const { auto ret = (iter != other.iter); if (not ret) cout << '\n'; return ret; } auto &operator++() { ++iter; if (iter != ed) cout << ' '; return *this; } auto &operator*() { return *iter; } }; struct iterable_wrapper { T iterable; auto begin() const { return iterator{std::begin(iterable), std::end(iterable)}; } auto end() const { return iterator{std::end(iterable), std::end(iterable)}; } }; return iterable_wrapper{forward<T>(iterable)}; }; template <size_t... Is, typename T> auto getis(const T &t) { return tie(get<Is>(t)...); } template <class T> void setmax(T &a, const T &b) { a = max(a, b); } template <class T> void setmin(T &a, const T &b) { a = min(a, b); } template <typename T> struct is_const_char_arr_ref : false_type {}; template <size_t N> struct is_const_char_arr_ref<char const (&)[N]> : true_type {}; template <typename T, typename = void> struct is_container : false_type {}; template <typename T> struct is_container<T, conditional_t<false, decltype(begin(declval<T>())), void>> : true_type {}; template <class T> using IsC = typename enable_if<is_container<T>::value and not is_same<T, string>::value>::type; template <class T> using NotC = typename enable_if<not is_container<T>::value or is_same<T, string>::value>::type; template <class T> inline IsC<T> print_1(const T &v); template <class T> inline NotC<T> print_1(const T &x) { cout << x; } template <size_t N> void print_1(const array<char, N> &x) { cout << &x[0]; }; inline void print_1(const tuple<> &) { cout << "()"; }; template <size_t L, size_t I, class T> void print_tuple(const T &t) { if (I != 0) cout << ", "; print_1(get<I>(t)); if (I + 1 < L) print_tuple<L, (I + 1) % L>(t); } template <class... T> inline void print_1(const tuple<T...> &x) { cout << "("; print_tuple<sizeof...(T), 0, tuple<T...>>(x); cout << ")"; } inline void print_n() {} template <class T, class... U> inline void print_n(const T &head, const U &...tail); template <class T, class U> inline void print_1(const pair<T, U> &p) { cout << "("; print_1(p.first); cout << ", "; print_1(p.second); cout << ")"; } template <class T, class... U> inline void print_n(const T &head, const U &...tail) { print_1(head); if (sizeof...(tail)) cout << " "; print_n(tail...); } template <class T> inline IsC<T> print_1(const T &v) { cout << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) cout << ", "; print_1(*it); } cout << "]"; } template <class... T> inline void print(const T &...args) { print_n(args...); putchar('\n'); } inline void read() {} template <class T, class... U> inline void read(T &head, U &...tail) { cin >> head; read(tail...); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); static int fastio = []() { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(17); return 0; }(); template <class T> void print_dbg(const string &s, T &&x) { if (is_const_char_arr_ref<T>::value) { print_n(x); } else { print_n(s, "=", x); } } #define SELECT(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME #define dbg1(a) \ print_dbg(#a, a); \ cout << endl; #define dbg2(a, b) \ print_dbg(#a, a); \ cout << ", "; \ dbg1(b); #define dbg3(a, b, c) \ print_dbg(#a, a); \ cout << ", "; \ dbg2(b, c); #define dbg4(a, b, c, d) \ print_dbg(#a, a); \ cout << ", "; \ dbg3(b, c, d); #define dbg5(a, b, c, d, e) \ print_dbg(#a, a); \ cout << ", "; \ dbg4(b, c, d, e); #define dbg6(a, b, c, d, e, f) \ print_dbg(#a, a); \ cout << ", "; \ dbg5(b, c, d, e, f); #define dbg7(a, b, c, d, e, f, g) \ print_dbg(#a, a); \ cout << ", "; \ dbg6(b, c, d, e, f, g); #define dbg8(a, b, c, d, e, f, g, h) \ print_dbg(#a, a); \ cout << ", "; \ dbg7(b, c, d, e, f, g, h); #define debug(...) \ SELECT(__VA_ARGS__, dbg8, dbg7, dbg6, dbg5, dbg4, dbg3, dbg2, dbg1) \ (__VA_ARGS__) //}}} using PII = pair<int, int>; using LL = long long; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const LL LLINF = 0x3f3f3f3f3f3f3f3f; const int MAX_N = 300005; array<array<array<double, 301>, 301>, 301> dp = {}; struct Solution { int N; double dfs(int i, int j, int k) { if (dp[i][j][k] > -0.5) { return dp[i][j][k]; } double y = 0.0; if (i > 0) { y += double(i) / N * dfs(i - 1, j, k); } if (j > 0) { y += double(j) / N * dfs(i + 1, j - 1, k); } if (k > 0) { y += double(k) / N * dfs(i, j + 1, k - 1); } double a = 1.0 - double(N - i - j - k) / N; double x = (1.0 + y) / a; dp[i][j][k] = x; return x; } Solution(int) { read(N); array<int, 4> cnt; for (repeat(N)) { int a; read(a); cnt[a] += 1; } for (int i : range(N + 1)) { for (int j : range(N + 1)) { for (int k : range(N + 1)) { dp[i][j][k] = -1.0; } } } dp[0][0][0] = 0.0; print(dfs(cnt[1], cnt[2], cnt[3])); } }; int main() { int T = 1; // cin >> T; for (int i = 1; i <= T; ++i) { ignore = Solution(i); } return 0; }
//{{{ #include <bits/stdc++.h> using namespace std; #define putchar(x) cout << (x) #define repeat(x) \ int _ = 0; \ _ < (x); \ ++_ template <typename T> constexpr auto range(T start, T stop, T step) { struct iterator { T i, step; bool operator!=(const iterator &other) const { return i != other.i; } auto &operator++() { i += step; return *this; } auto &operator*() { return i; } }; struct iterable_wrapper { T start, stop, step; auto begin() const { return iterator{start, step}; } auto end() const { return iterator{stop, step}; } size_t size() const { return (stop - start) / step; } iterable_wrapper(T start_, T stop_, T step_) : start(start_), stop(stop_), step(step_) { stop = step > 0 ? max(start, stop) : min(start, stop); stop += (step - (stop - start) % step) % step; } }; return iterable_wrapper(start, stop, step); }; template <typename T> constexpr auto range(T start, T stop) { return range(start, stop, T(1)); } template <typename T> constexpr auto range(T stop) { return range(T(0), stop, T(1)); } template <typename T, typename Iter = decltype(begin(declval<T>()))> constexpr auto printer(T &&iterable) { struct iterator { Iter iter, ed; auto operator!=(const iterator &other) const { auto ret = (iter != other.iter); if (not ret) cout << '\n'; return ret; } auto &operator++() { ++iter; if (iter != ed) cout << ' '; return *this; } auto &operator*() { return *iter; } }; struct iterable_wrapper { T iterable; auto begin() const { return iterator{std::begin(iterable), std::end(iterable)}; } auto end() const { return iterator{std::end(iterable), std::end(iterable)}; } }; return iterable_wrapper{forward<T>(iterable)}; }; template <size_t... Is, typename T> auto getis(const T &t) { return tie(get<Is>(t)...); } template <class T> void setmax(T &a, const T &b) { a = max(a, b); } template <class T> void setmin(T &a, const T &b) { a = min(a, b); } template <typename T> struct is_const_char_arr_ref : false_type {}; template <size_t N> struct is_const_char_arr_ref<char const (&)[N]> : true_type {}; template <typename T, typename = void> struct is_container : false_type {}; template <typename T> struct is_container<T, conditional_t<false, decltype(begin(declval<T>())), void>> : true_type {}; template <class T> using IsC = typename enable_if<is_container<T>::value and not is_same<T, string>::value>::type; template <class T> using NotC = typename enable_if<not is_container<T>::value or is_same<T, string>::value>::type; template <class T> inline IsC<T> print_1(const T &v); template <class T> inline NotC<T> print_1(const T &x) { cout << x; } template <size_t N> void print_1(const array<char, N> &x) { cout << &x[0]; }; inline void print_1(const tuple<> &) { cout << "()"; }; template <size_t L, size_t I, class T> void print_tuple(const T &t) { if (I != 0) cout << ", "; print_1(get<I>(t)); if (I + 1 < L) print_tuple<L, (I + 1) % L>(t); } template <class... T> inline void print_1(const tuple<T...> &x) { cout << "("; print_tuple<sizeof...(T), 0, tuple<T...>>(x); cout << ")"; } inline void print_n() {} template <class T, class... U> inline void print_n(const T &head, const U &...tail); template <class T, class U> inline void print_1(const pair<T, U> &p) { cout << "("; print_1(p.first); cout << ", "; print_1(p.second); cout << ")"; } template <class T, class... U> inline void print_n(const T &head, const U &...tail) { print_1(head); if (sizeof...(tail)) cout << " "; print_n(tail...); } template <class T> inline IsC<T> print_1(const T &v) { cout << "["; for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) cout << ", "; print_1(*it); } cout << "]"; } template <class... T> inline void print(const T &...args) { print_n(args...); putchar('\n'); } inline void read() {} template <class T, class... U> inline void read(T &head, U &...tail) { cin >> head; read(tail...); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); static int fastio = []() { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(17); return 0; }(); template <class T> void print_dbg(const string &s, T &&x) { if (is_const_char_arr_ref<T>::value) { print_n(x); } else { print_n(s, "=", x); } } #define SELECT(_1, _2, _3, _4, _5, _6, _7, _8, NAME, ...) NAME #define dbg1(a) \ print_dbg(#a, a); \ cout << endl; #define dbg2(a, b) \ print_dbg(#a, a); \ cout << ", "; \ dbg1(b); #define dbg3(a, b, c) \ print_dbg(#a, a); \ cout << ", "; \ dbg2(b, c); #define dbg4(a, b, c, d) \ print_dbg(#a, a); \ cout << ", "; \ dbg3(b, c, d); #define dbg5(a, b, c, d, e) \ print_dbg(#a, a); \ cout << ", "; \ dbg4(b, c, d, e); #define dbg6(a, b, c, d, e, f) \ print_dbg(#a, a); \ cout << ", "; \ dbg5(b, c, d, e, f); #define dbg7(a, b, c, d, e, f, g) \ print_dbg(#a, a); \ cout << ", "; \ dbg6(b, c, d, e, f, g); #define dbg8(a, b, c, d, e, f, g, h) \ print_dbg(#a, a); \ cout << ", "; \ dbg7(b, c, d, e, f, g, h); #define debug(...) \ SELECT(__VA_ARGS__, dbg8, dbg7, dbg6, dbg5, dbg4, dbg3, dbg2, dbg1) \ (__VA_ARGS__) //}}} using PII = pair<int, int>; using LL = long long; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; const LL LLINF = 0x3f3f3f3f3f3f3f3f; const int MAX_N = 300005; array<array<array<double, 301>, 301>, 301> dp = {}; struct Solution { int N; double dfs(int i, int j, int k) { if (dp[i][j][k] > -0.5) { return dp[i][j][k]; } double y = 0.0; if (i > 0) { y += double(i) / N * dfs(i - 1, j, k); } if (j > 0) { y += double(j) / N * dfs(i + 1, j - 1, k); } if (k > 0) { y += double(k) / N * dfs(i, j + 1, k - 1); } double a = 1.0 - double(N - i - j - k) / N; double x = (1.0 + y) / a; dp[i][j][k] = x; return x; } Solution(int) { read(N); array<int, 4> cnt = {}; for (repeat(N)) { int a; read(a); cnt[a] += 1; } for (int i : range(N + 1)) { for (int j : range(N + 1)) { for (int k : range(N + 1)) { dp[i][j][k] = -1.0; } } } dp[0][0][0] = 0.0; print(dfs(cnt[1], cnt[2], cnt[3])); } }; int main() { int T = 1; // cin >> T; for (int i = 1; i <= T; ++i) { ignore = Solution(i); } return 0; }
[ "variable_declaration.value.change" ]
977,865
977,866
u097873932
cpp
p03169
#include <bits/stdc++.h> using namespace std; const int MAXN = 302; int n; double dp[MAXN][MAXN][MAXN]; bool vis[MAXN][MAXN][MAXN]; double solve(int x, int y, int z) { if (vis[x][y][z]) return dp[x][y][z]; vis[x][y][z] = 1; if (!x && !y && !z) return dp[x][y][z] = 0; int total = x + y + z; double tot = (n - total) / total; if (x != 0) tot += x * ((solve(x - 1, y, z) + 1) / total); if (y != 0) tot += y * ((solve(x + 1, y - 1, z) + 1) / total); if (z != 0) tot += z * ((solve(x, y + 1, z - 1) + 1) / total); return dp[x][y][z] = tot; } int main() { int a[4] = {0, 0, 0, 0}; cin >> n; for (int i = 1; i <= n; ++i) { int x; cin >> x; ++a[x]; } cout.precision(10); cout << solve(a[1], a[2], a[3]); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 302; int n; double dp[MAXN][MAXN][MAXN]; bool vis[MAXN][MAXN][MAXN]; double solve(int x, int y, int z) { if (vis[x][y][z]) return dp[x][y][z]; vis[x][y][z] = 1; if (!x && !y && !z) return dp[x][y][z] = 0; int total = x + y + z; double tot = (double)(n - total) / total; if (x != 0) tot += x * ((solve(x - 1, y, z) + 1) / total); if (y != 0) tot += y * ((solve(x + 1, y - 1, z) + 1) / total); if (z != 0) tot += z * ((solve(x, y + 1, z - 1) + 1) / total); return dp[x][y][z] = tot; } int main() { int a[4] = {0, 0, 0, 0}; cin >> n; for (int i = 1; i <= n; ++i) { int x; cin >> x; ++a[x]; } cout.precision(10); cout << solve(a[1], a[2], a[3]); return 0; }
[ "type_conversion.add" ]
977,875
977,876
u158312277
cpp
p03169
#ifndef BZ #pragma GCC optimize "-Ofast" #endif #include <bits/stdc++.h> #define FASTIO #define ALL(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (l); i < (r); ++i) #ifdef FASTIO #define scanf abacaba #define printf abacaba #endif typedef long long ll; typedef double ld; typedef unsigned long long ull; using namespace std; const int MX = 307; ld f[MX + 5][MX + 5][MX + 5]; int main() { #ifdef FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #endif int n; cin >> n; int c1 = 0, c2 = 0, c3 = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 1) { c1++; } else if (x == 2) { c2++; } else { c3++; } } for (int k = 0; k < MX; k++) { for (int j = 0; j + k < MX; j++) { for (int i = 0; i + j + k < MX; i++) { if (i == 0 && j == 0 && k == 0) { continue; } if (i + j + k > MX) { continue; } ld wait = 1.0 * n / (i + j + k); ld pi = 1.0 * i / (i + j + k); ld pj = 1.0 * j / (i + j + k); ld pk = 1.0 * k / (i + j + k); if (i) { f[i][j][k] = pi * f[i - 1][j][k]; } if (j) { f[i][j][k] = pj * f[i + 1][j - 1][k]; } if (k) { f[i][j][k] = pk * f[i][j + 1][k - 1]; } f[i][j][k] += wait; } } } cout.precision(10); cout << fixed << f[c1][c2][c3] << "\n"; return 0; }
#ifndef BZ #pragma GCC optimize "-Ofast" #endif #include <bits/stdc++.h> #define FASTIO #define ALL(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (l); i < (r); ++i) #ifdef FASTIO #define scanf abacaba #define printf abacaba #endif typedef long long ll; typedef double ld; typedef unsigned long long ull; using namespace std; const int MX = 307; ld f[MX + 5][MX + 5][MX + 5]; int main() { #ifdef FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #endif int n; cin >> n; int c1 = 0, c2 = 0, c3 = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 1) { c1++; } else if (x == 2) { c2++; } else { c3++; } } for (int k = 0; k < MX; k++) { for (int j = 0; j + k < MX; j++) { for (int i = 0; i + j + k < MX; i++) { if (i == 0 && j == 0 && k == 0) { continue; } if (i + j + k > MX) { continue; } ld wait = 1.0 * n / (i + j + k); ld pi = 1.0 * i / (i + j + k); ld pj = 1.0 * j / (i + j + k); ld pk = 1.0 * k / (i + j + k); if (i) { f[i][j][k] = pi * f[i - 1][j][k]; } if (j) { f[i][j][k] += pj * f[i + 1][j - 1][k]; } if (k) { f[i][j][k] += pk * f[i][j + 1][k - 1]; } f[i][j][k] += wait; } } } cout.precision(10); cout << fixed << f[c1][c2][c3] << "\n"; return 0; }
[ "assignment.value.change" ]
977,878
977,879
u279347994
cpp
p03169
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; map<int, int> mp; for (auto it : a) { mp[it]++; } int N = n + 5; double dp[N][N][N]; // dp[i][j][k]:1枚の皿がi枚、2枚の皿がj枚、3枚の皿がk枚あったときの期待値 for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) dp[i][j][k] = 0; } } for (int k = 0; k < N; k++) { for (int j = 0; j < N; j++) { for (int i = 0; i < N; i++) { double m = double(n); double p1 = double(i) / m, p2 = double(j) / m, p3 = double(k) / m; double sum = p1 + p2 + p3; if (i == 0 && j == 0 && k == 0) continue; dp[i][j][k] = 1; if (i != 0) dp[i][j][k] += dp[i - 1][j][k] * p1; if (j != 0) dp[i][j][k] += dp[i + 1][j - 1][k] * p2; if (k != 0) dp[i][j][k] += dp[i][j + 1][k - 1] * p3; dp[i][j][k] /= sum; } } } cout << setprecision(20) << dp[mp[1]][mp[2]][mp[3]] << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; map<int, int> mp; for (auto it : a) { mp[it]++; } int N = n + 5; double dp[N][N][N]; // dp[i][j][k]:1枚の皿がi枚、2枚の皿がj枚、3枚の皿がk枚あったときの期待値 for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) dp[i][j][k] = 0; } } for (int k = 0; k < N - 1; k++) { for (int j = 0; j < N - 1; j++) { for (int i = 0; i < N - 1; i++) { double m = double(n); double p1 = double(i) / m, p2 = double(j) / m, p3 = double(k) / m; double sum = p1 + p2 + p3; if (i == 0 && j == 0 && k == 0) continue; dp[i][j][k] = 1; if (i != 0) dp[i][j][k] += dp[i - 1][j][k] * p1; if (j != 0) dp[i][j][k] += dp[i + 1][j - 1][k] * p2; if (k != 0) dp[i][j][k] += dp[i][j + 1][k - 1] * p3; dp[i][j][k] /= sum; } } } cout << setprecision(20) << dp[mp[1]][mp[2]][mp[3]] << endl; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
977,880
977,881
u282228874
cpp
p03169
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; //#define int ll //#define endl '\n' // use unique(x) - removec consecutive items, returns vec.begin() + number of // items for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end()); use // iota(all(vec), 0) for filling a vector with 0,1,2... use fill(all(vec), 1) // for filling a vector with 1,1,1... use rotate(vec.begin(), vec.begin() + 1, // vec.end()) to rotate a vector | middle arg becomes first print number in // binary -> cout << bitset<20>(n); const int N = 303, mod = 1e9 + 7; int n; int cnt[4]; ld dp[N][N][N], ev[N][N][N]; main() { cin.tie(0); cin.sync_with_stdio(0); cin >> n; for (int i = 0; i < n; ++i) { int a; cin >> a; ++cnt[a]; } dp[cnt[1]][cnt[2]][cnt[3]] = 1; for (int k = n; k >= 0; --k) for (int j = n; j >= 0; --j) for (int i = n; i >= 0; --i) if (i || j || k) { ld pwaste = ld(n - (i + j + k)) / n; ld evwaste = pwaste / (1 - pwaste) + 1; ev[i][j][k] += evwaste * dp[i][j][k]; if (i) dp[i - 1][j][k] += dp[i][j][k] * i / (i + j + k); if (j) dp[i + 1][j - 1][k] += dp[i][j][k] * j / (i + j + k); if (k) dp[i][j + 1][k - 1] += dp[i][j][k] * k / (i + j + k); if (i) ev[i - 1][j][k] += ev[i][j][k] * i / (i + j + k); if (j) ev[i + 1][j - 1][k] += ev[i][j][k] * j / (i + j + k); if (k) ev[i][j + 1][k - 1] += ev[i][j][k] * k / (i + j + k); } cout << setprecision(10) << fixed << ev[0][0][0] << endl; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; //#define int ll //#define endl '\n' // use unique(x) - removec consecutive items, returns vec.begin() + number of // items for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end()); use // iota(all(vec), 0) for filling a vector with 0,1,2... use fill(all(vec), 1) // for filling a vector with 1,1,1... use rotate(vec.begin(), vec.begin() + 1, // vec.end()) to rotate a vector | middle arg becomes first print number in // binary -> cout << bitset<20>(n); const int N = 303, mod = 1e9 + 7; int n; int cnt[4]; double dp[N][N][N], ev[N][N][N]; main() { cin.tie(0); cin.sync_with_stdio(0); cin >> n; for (int i = 0; i < n; ++i) { int a; cin >> a; ++cnt[a]; } dp[cnt[1]][cnt[2]][cnt[3]] = 1; for (int k = n; k >= 0; --k) for (int j = n; j >= 0; --j) for (int i = n; i >= 0; --i) if (i || j || k) { double pwaste = double(n - (i + j + k)) / n; double evwaste = pwaste / (1 - pwaste) + 1; ev[i][j][k] += evwaste * dp[i][j][k]; if (i) dp[i - 1][j][k] += dp[i][j][k] * i / (i + j + k); if (j) dp[i + 1][j - 1][k] += dp[i][j][k] * j / (i + j + k); if (k) dp[i][j + 1][k - 1] += dp[i][j][k] * k / (i + j + k); if (i) ev[i - 1][j][k] += ev[i][j][k] * i / (i + j + k); if (j) ev[i + 1][j - 1][k] += ev[i][j][k] * j / (i + j + k); if (k) ev[i][j + 1][k - 1] += ev[i][j][k] * k / (i + j + k); } cout << setprecision(10) << fixed << ev[0][0][0] << endl; }
[ "variable_declaration.type.change", "call.function.change", "expression.operation.binary.change" ]
977,902
977,903
u711923246
cpp
p03169
#include <bits/stdc++.h> using namespace std; double dp[301][301][301]; double solve(int x, int y, int z, int &n) { if (x < 0 || y < 0 || z < 0) return 0; if (x == 0 && y == 0 && z == 0) return 0; if (dp[x][y][z] > -0.9) return dp[x][y][z]; int exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n); return dp[x][y][z] = exp / (x + y + z); } int main() { int n; cin >> n; memset(dp, -1, sizeof dp); int ones = 0, twos = 0, threes = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) ones++; else if (a == 2) twos++; else threes++; } cout << fixed << setprecision(10) << solve(ones, twos, threes, n); return 0; }
#include <bits/stdc++.h> using namespace std; double dp[301][301][301]; double solve(int x, int y, int z, int &n) { if (x < 0 || y < 0 || z < 0) return 0; if (x == 0 && y == 0 && z == 0) return 0; if (dp[x][y][z] > -0.9) return dp[x][y][z]; double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n); return dp[x][y][z] = exp / (x + y + z); } int main() { int n; cin >> n; memset(dp, -1, sizeof dp); int ones = 0, twos = 0, threes = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) ones++; else if (a == 2) twos++; else threes++; } cout << fixed << setprecision(10) << solve(ones, twos, threes, n); return 0; }
[ "variable_declaration.type.primitive.change" ]
977,917
977,918
u495505677
cpp
p03169
#include <bits/stdc++.h> using namespace std; #define ll long long int #define vl vector<long long int> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define all(x) x.begin(), x.end() #define vi vector<int> #define vb vector<bool> #define vvl vector<vector<ll>> #define vvi vector<vector<int>> #define pl pair<ll, ll> #define pb push_back #define PI 3.14159265 #define mod 998244353 #define pb push_back #define mp make_pair #define fri(s, n) for (int i = s; i < n; i++) #define frj(s, n) for (int j = s; j < n; j++) #define T(i) \ int i = 1; \ cin >> i; \ while (i--) #define vsi vector<set<int>> #define pii pair<int, int> #define inf 1e9 #define vpii vector<pair<int, int>> ll power(ll a, ll b) { if (b == 0) return 1; if (b & 1) return a * power(a, b - 1); ll temp = power(a, b / 2); return temp * temp; } bool mycompare(ll a, ll b) { return a > b; } double dp[301][301][301]; double trials(int x, int y, int z, int n) { if (x < 0 || y < 0 || z < 0) return 0.0; if (x == 0 && y == 0 && z == 0) return 0.0; // cout<<x<<" "<<y<<" "<<z<<"\n"; if (dp[x][y][z] != -1.0) return dp[x][y][z]; return dp[x][y][z] = (n + x * trials(x - 1, y, z, n) + y * trials(x + 1, y - 1, z, n) + z * trials(x, y + 1, z - 1, n)) / (x + y + z); } int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); fast; int n; cin >> n; int x = 0, y = 0, z = 0; fri(0, n) { int temp; cin >> temp; if (temp == 1) x++; else if (temp == 2) y++; else z++; } memset(dp, -1.0, sizeof dp); // vector<vector<vector<double> > > dp(x+1,vector<vector<double> // >(y+1,vector<double>(z+1,-1.0))); cout << setprecision(15) << trials(x, y, z, n); }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define vl vector<long long int> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define all(x) x.begin(), x.end() #define vi vector<int> #define vb vector<bool> #define vvl vector<vector<ll>> #define vvi vector<vector<int>> #define pl pair<ll, ll> #define pb push_back #define PI 3.14159265 #define mod 998244353 #define pb push_back #define mp make_pair #define fri(s, n) for (int i = s; i < n; i++) #define frj(s, n) for (int j = s; j < n; j++) #define T(i) \ int i = 1; \ cin >> i; \ while (i--) #define vsi vector<set<int>> #define pii pair<int, int> #define inf 1e9 #define vpii vector<pair<int, int>> ll power(ll a, ll b) { if (b == 0) return 1; if (b & 1) return a * power(a, b - 1); ll temp = power(a, b / 2); return temp * temp; } bool mycompare(ll a, ll b) { return a > b; } double dp[301][301][301]; double trials(int x, int y, int z, int n) { if (x < 0 || y < 0 || z < 0) return 0.0; if (x == 0 && y == 0 && z == 0) return 0.0; // cout<<x<<" "<<y<<" "<<z<<"\n"; if (dp[x][y][z] > -0.1) return dp[x][y][z]; return dp[x][y][z] = (n + x * trials(x - 1, y, z, n) + y * trials(x + 1, y - 1, z, n) + z * trials(x, y + 1, z - 1, n)) / (x + y + z); } int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); fast; int n; cin >> n; int x = 0, y = 0, z = 0; fri(0, n) { int temp; cin >> temp; if (temp == 1) x++; else if (temp == 2) y++; else z++; } memset(dp, -1.0, sizeof dp); // vector<vector<vector<double> > > dp(x+1,vector<vector<double> // >(y+1,vector<double>(z+1,-1.0))); cout << setprecision(15) << trials(x, y, z, n); }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "literal.number.change" ]
977,938
977,939
u709648815
cpp
p03169
#include <bits/stdc++.h> double dp[301][301][301]; using namespace std; void setdp() { for (int i = 1; i < 301; i++) { for (int j = 1; j < 301; j++) { for (int k = 1; k < 301; k++) { dp[i][j][k] = -1; } } } } double solve(int x, int y, int z, int n) { if (x < 0 || y < 0 || z < 0) { return 0; } if (x == 0 && y == 0 && z == 0) { return 0; } if (dp[x][y][z] > -0.9) { return dp[x][y][z]; } double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n); return dp[x][y][z] = exp / (x + y + z); } int main() { int n; cin >> n; int one = 0, two = 0, three = 0; setdp(); for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 1) { one++; } else if (x == 2) { two++; } else { three++; } } cout << fixed << setprecision(10) << solve(one, two, three, n); }
#include <bits/stdc++.h> double dp[301][301][301]; using namespace std; void setdp() { for (int i = 0; i < 301; i++) { for (int j = 0; j < 301; j++) { for (int k = 0; k < 301; k++) { dp[i][j][k] = -1; } } } } double solve(int x, int y, int z, int &n) { if (x < 0 || y < 0 || z < 0) { return 0; } if (x == 0 && y == 0 && z == 0) { return 0; } if (dp[x][y][z] > -0.9) { return dp[x][y][z]; } double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n); return dp[x][y][z] = exp / (x + y + z); } int main() { int n; cin >> n; int one = 0, two = 0, three = 0; setdp(); for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 1) { one++; } else if (x == 2) { two++; } else { three++; } } cout << fixed << setprecision(10) << solve(one, two, three, n); }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
977,958
977,956
u973316555
cpp
p03169
#include <bits/stdc++.h> using namespace std; #define pr_double(x) cout << fixed << setprecision(10) << x; double dp[301][301][301]; double solve(int x, int y, int z, int &n) { if (x < 0 || y < 0 || z < 0) { return 0; } if (x == 0 && y == 0 && z == 0) { return 0; } if (dp[x][y][z] > -0.9) { return dp[x][y][z]; } double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n); return dp[x][y][z] = (double)exp / x + y + z; } int main() { int n, x; cin >> n; memset(dp, -1, sizeof dp); int one = 0, two = 0, three = 0; for (int i = 1; i <= n; i++) { cin >> x; if (x == 1) { one++; } else if (x == 2) { two++; } else { three++; } } pr_double(solve(one, two, three, n)); }
#include <bits/stdc++.h> using namespace std; #define pr_double(x) cout << fixed << setprecision(10) << x; double dp[301][301][301]; double solve(int x, int y, int z, int &n) { if (x < 0 || y < 0 || z < 0) { return 0; } if (x == 0 && y == 0 && z == 0) { return 0; } if (dp[x][y][z] > -0.9) { return dp[x][y][z]; } double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n); return dp[x][y][z] = (double)exp / (x + y + z); } int main() { int n, x; cin >> n; memset(dp, -1, sizeof dp); int one = 0, two = 0, three = 0; for (int i = 1; i <= n; i++) { cin >> x; if (x == 1) { one++; } else if (x == 2) { two++; } else { three++; } } pr_double(solve(one, two, three, n)); }
[ "function.return_value.change" ]
977,959
977,960
u983104183
cpp
p03169
#include <bits/stdc++.h> using namespace std; #define pr_double(x) cout << fixed << setprecision(10) << x; double dp[301][301][301]; double solve(int x, int y, int z, int &n) { if (x < 0 || y < 0 || z < 0) { return 0; } if (x == 0 && y == 0 && z == 0) { return 0; } if (dp[x][y][z] > -0.9) { return dp[x][y][z]; } double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n); return dp[x][y][z] = exp / x + y + z; } int main() { int n, x; cin >> n; memset(dp, -1, sizeof dp); int one = 0, two = 0, three = 0; for (int i = 1; i <= n; i++) { cin >> x; if (x == 1) { one++; } else if (x == 2) { two++; } else { three++; } } pr_double(solve(one, two, three, n)); }
#include <bits/stdc++.h> using namespace std; #define pr_double(x) cout << fixed << setprecision(10) << x; double dp[301][301][301]; double solve(int x, int y, int z, int &n) { if (x < 0 || y < 0 || z < 0) { return 0; } if (x == 0 && y == 0 && z == 0) { return 0; } if (dp[x][y][z] > -0.9) { return dp[x][y][z]; } double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n); return dp[x][y][z] = (double)exp / (x + y + z); } int main() { int n, x; cin >> n; memset(dp, -1, sizeof dp); int one = 0, two = 0, three = 0; for (int i = 1; i <= n; i++) { cin >> x; if (x == 1) { one++; } else if (x == 2) { two++; } else { three++; } } pr_double(solve(one, two, three, n)); }
[ "function.return_value.change" ]
977,961
977,960
u983104183
cpp
p03169
#include <bits/stdc++.h> using namespace std; double dp[301][301][301]; double solve(int x, int y, int z, int &n) { if (x < 0 || y < 0 || z < 0) return 0; if (x == 0 && y == 0 && z == 0) return 0; if (dp[x][y][z] > -0.9) return dp[x][y][z]; double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y, z, n) + z * solve(x, y + 1, z - 1, n); return dp[x][y][z] = exp / (x + y + z); } int main() { int n; cin >> n; vector<int> vec(n + 1); int one = 0, two = 0, three = 0; memset(dp, -1, sizeof dp); for (int i = 1; i <= n; i++) { cin >> vec[i]; if (vec[i] == 1) one++; else if (vec[i] == 2) two++; else three++; } double ans = solve(one, two, three, n); cout << fixed << setprecision(10) << ans; return 0; }
#include <bits/stdc++.h> using namespace std; double dp[301][301][301]; double solve(int x, int y, int z, int &n) { if (x < 0 || y < 0 || z < 0) return 0; if (x == 0 && y == 0 && z == 0) return 0; if (dp[x][y][z] > -0.9) return dp[x][y][z]; double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n); return dp[x][y][z] = exp / (x + y + z); } int main() { int n; cin >> n; vector<int> vec(n + 1); int one = 0, two = 0, three = 0; memset(dp, -1, sizeof dp); for (int i = 1; i <= n; i++) { cin >> vec[i]; if (vec[i] == 1) one++; else if (vec[i] == 2) two++; else three++; } double ans = solve(one, two, three, n); cout << fixed << setprecision(14) << ans; return 0; }
[ "literal.number.change", "io.output.change" ]
977,962
977,963
u922620013
cpp
p03169
#include <bits/stdc++.h> using namespace std; double dp[301][301][301]; double solve(int x, int y, int z, int &n) { if (x < 0 || y < 0 || z < 0) { return 0; } if (dp[x][y][z] > -0.9) { return dp[x][y][z]; } if (x == 0 && y == 0 && z == 0) { return 0; } double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n); return dp[x][y][z] = (exp) / (x + y + z); } int main() { int n; cin >> n; int one, two, three; memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++) { int x; cin >> x; if (x == 1) { one++; } else if (x == 2) { two++; } else if (x == 3) { three++; } } cout << fixed << setprecision(10) << solve(one, two, three, n); }
#include <bits/stdc++.h> using namespace std; double dp[301][301][301]; double solve(int x, int y, int z, int &n) { if (x < 0 || y < 0 || z < 0) { return 0; } if (dp[x][y][z] > -0.9) { return dp[x][y][z]; } if (x == 0 && y == 0 && z == 0) { return 0; } double exp = n + x * solve(x - 1, y, z, n) + y * solve(x + 1, y - 1, z, n) + z * solve(x, y + 1, z - 1, n); return dp[x][y][z] = (exp) / (x + y + z); } int main() { int n; cin >> n; int one = 0, two = 0, three = 0; memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++) { int x; cin >> x; if (x == 1) { one++; } else if (x == 2) { two++; } else if (x == 3) { three++; } } cout << fixed << setprecision(10) << solve(one, two, three, n); }
[ "variable_declaration.value.change" ]
977,968
977,969
u348267046
cpp
p03169
#include <bits/stdc++.h> using namespace std; using ll = long long int; #define rep(i, n) for (int i = 0; i < (n); i++) int n; double dp[310][310][310]; double rec(int a, int b, int c) { if (dp[a][b][c] >= 0) return dp[a][b][c]; if (a == 0 && b == 0 && c == 0) return 0.0; double res = 0.0; if (a > 0) res += rec(a - 1, b, c) * a; if (b > 0) res += rec(a, b - 1, c) * b; if (c > 0) res += rec(a, b, c - 1) * c; res += n; res *= 1.0 / (a + b + c); return dp[a][b][c] = res; } int main() { cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; int one = 0, two = 0, three = 0; rep(i, n) { if (a[i] == 1) one += 1; if (a[i] == 2) two += 1; if (a[i] == 3) three += 1; } memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << rec(one, two, three) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; #define rep(i, n) for (int i = 0; i < (n); i++) int n; double dp[310][310][310]; double rec(int a, int b, int c) { if (dp[a][b][c] >= 0) return dp[a][b][c]; if (a == 0 && b == 0 && c == 0) return 0.0; double res = 0.0; if (a > 0) res += rec(a - 1, b, c) * a; if (b > 0) res += rec(a + 1, b - 1, c) * b; if (c > 0) res += rec(a, b + 1, c - 1) * c; res += n; res *= 1.0 / (a + b + c); return dp[a][b][c] = res; } int main() { cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; int one = 0, two = 0, three = 0; rep(i, n) { if (a[i] == 1) one += 1; if (a[i] == 2) two += 1; if (a[i] == 3) three += 1; } memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << rec(one, two, three) << endl; }
[ "assignment.change" ]
977,972
977,973
u436660228
cpp
p03169
#include <bits/stdc++.h> #define ll long long #define MAX 300005 #define pp pair<int, pair<int, int>> #define pb push_back #define mod 1000000007 #define mx 305 using namespace std; /* * author: Kruti_20 */ ll power(ll x, ll y); ll gcd(ll a, ll b); double dp[mx][mx][mx]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int c1 = 0, c2 = 0, c3 = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 1) c1++; else if (x == 2) c2++; else c3++; } for (int i = 0; i < mx; i++) { for (int j = 0; i + j < mx; j++) { for (int k = 0; i + j + k < mx; k++) { if (i == 0 && j == 0 && k == 0) continue; if (i) dp[i][j][k] += ((1.0 * i) / (i + j + k)) * dp[i - 1][j][k]; if (j) dp[i][j][k] += ((1.0 * j) / (i + j + k)) * dp[i + 1][j - 1][k]; if (k) dp[i][j][k] += ((1.0 * k) / (i + j + k)) * dp[i][j + 1][k - 1]; dp[i][j][k] += (1.0 * n) / (i + j + k); } } } cout << fixed << setprecision(10) << dp[c1][c2][c3]; return 0; } ll power(ll x, ll y) { ll res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
#include <bits/stdc++.h> #define ll long long #define MAX 300005 #define pp pair<int, pair<int, int>> #define pb push_back #define mod 1000000007 #define mx 305 using namespace std; /* * author: Kruti_20 */ ll power(ll x, ll y); ll gcd(ll a, ll b); double dp[mx][mx][mx]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int c1 = 0, c2 = 0, c3 = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x == 1) c1++; else if (x == 2) c2++; else c3++; } for (int k = 0; k < mx; k++) { for (int j = 0; k + j < mx; j++) { for (int i = 0; i + j + k < mx; i++) { if (i == 0 && j == 0 && k == 0) continue; if (i) dp[i][j][k] += ((1.0 * i) / (i + j + k)) * dp[i - 1][j][k]; if (j) dp[i][j][k] += ((1.0 * j) / (i + j + k)) * dp[i + 1][j - 1][k]; if (k) dp[i][j][k] += ((1.0 * k) / (i + j + k)) * dp[i][j + 1][k - 1]; dp[i][j][k] += (1.0 * n) / (i + j + k); } } } cout << fixed << setprecision(10) << dp[c1][c2][c3]; return 0; } ll power(ll x, ll y) { ll res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
[ "variable_declaration.name.change", "identifier.change", "control_flow.loop.for.initializer.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
978,000
978,001
u352059674
cpp
p03169
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()) #define VRSORT(v) sort(v.rbegin(), v.rend()) #define ll long long #define pb(a) push_back(a) #define INF 1000000000 #define MOD 1000000007 using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; typedef vector<unsigned int> vec; typedef vector<vec> mat; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline void add(T &a, T b) { a = ((a + b) % MOD + MOD) % MOD; }; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; int N; double dp[310][310][310]; double rec(int i, int j, int k) { if (dp[i][j][k] >= 0) return dp[i][j][k]; if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; if (i > 0) res += rec(i - 1, j, k) * i; if (j > 0) res += rec(i, j - 1, k) * j; if (k > 0) res += rec(i, j, k - 1) * k; res += N; res *= 1.0 / (i + j + k); return dp[i][j][k] = res; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; int one = 0, two = 0, three = 0; REP(i, N) { int a; cin >> a; if (a == 1) one++; else if (a == 2) two++; else three++; } memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << rec(one, two, three) << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()) #define VRSORT(v) sort(v.rbegin(), v.rend()) #define ll long long #define pb(a) push_back(a) #define INF 1000000000 #define MOD 1000000007 using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; typedef vector<unsigned int> vec; typedef vector<vec> mat; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline void add(T &a, T b) { a = ((a + b) % MOD + MOD) % MOD; }; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; int N; double dp[310][310][310]; double rec(int i, int j, int k) { if (dp[i][j][k] >= 0) return dp[i][j][k]; if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; if (i > 0) res += rec(i - 1, j, k) * i; if (j > 0) res += rec(i + 1, j - 1, k) * j; if (k > 0) res += rec(i, j + 1, k - 1) * k; res += N; res *= 1.0 / (i + j + k); return dp[i][j][k] = res; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; int one = 0, two = 0, three = 0; REP(i, N) { int a; cin >> a; if (a == 1) one++; else if (a == 2) two++; else three++; } memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << rec(one, two, three) << endl; }
[ "assignment.change" ]
978,002
978,003
u493750228
cpp
p03169
#include <bits/stdc++.h> using namespace std; int n; int a[4]; double dp[305][305][305]; void solve() { dp[0][0][0] = 0; for (int k = 0; k <= 300; k++) for (int j = 0; j + k <= 300; j++) for (int i = 0; i + j + k <= 300; i++) { if (!i && !j && !k) continue; int N = i + j + k; if (i) dp[i][j][k] += dp[i - 1][j][k] * i / (1.0 * N); if (j) dp[i][j][k] += dp[i + 1][j - 1][k] * j / (1.0 * N); if (k) dp[i][j][k] += dp[i][j + 1][k - 1] * k / (1.0 * N); dp[i][j][k] += 1.0 * n / N; } printf(".12lf\n", dp[a[1]][a[2]][a[3]]); } int main() { scanf("%d", &n); for (int i = 1, u; i <= n; i++) { scanf("%d", &u); a[u]++; } solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int n; int a[4]; double dp[305][305][305]; void solve() { dp[0][0][0] = 0; for (int k = 0; k <= 300; k++) for (int j = 0; j + k <= 300; j++) for (int i = 0; i + j + k <= 300; i++) { if (!i && !j && !k) continue; int N = i + j + k; if (i) dp[i][j][k] += dp[i - 1][j][k] * i / (1.0 * N); if (j) dp[i][j][k] += dp[i + 1][j - 1][k] * j / (1.0 * N); if (k) dp[i][j][k] += dp[i][j + 1][k - 1] * k / (1.0 * N); dp[i][j][k] += 1.0 * n / N; } printf("%.12lf\n", dp[a[1]][a[2]][a[3]]); } int main() { scanf("%d", &n); for (int i = 1, u; i <= n; i++) { scanf("%d", &u); a[u]++; } solve(); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
978,006
978,007
u304050136
cpp
p03169
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 //なんで解けたか //何番目にあるかは対称性より関係ない //枚数が0-3だけなので状態がまとめられる // n枚で固定なので1個、2個、3個の枚数が決まればn-(i+j+k)で0個の皿の枚数が求まる //状態を3つ持つだけでいい300^3=9*10^6くらいで余裕 //遷移を書いたときに、遷移元と遷移先に同じ項が出てくる //どう解消するか→移項するだけ int n; double dp[310][310][310]; double rec(int i, int j, int k) { //メモってあればそれを使う if (dp[i][j][k] != -1.0) return dp[i][j][k]; //境界条件すべて0の状態から0枚にするのは自明に0枚必要 if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; // 1枚使った状態 値×確率を集める if (i > 0) res += rec(i - 1, j, k) * i; //残り1枚の皿が1枚減る if (j > 0) res += rec(i + 1, j - 1, k) * j; //残り2枚の皿が1枚減って、残り1枚になる if (k > 0) res += rec(i, j + 1, k - 1) * k; //残り3枚の皿が1枚減って、残り2枚の皿が1枚増える //+1にn/(i+j+k)をかけるとnになる。あとからまとめて(i+j+k)割るので、+n res += n; res *= 1.0 / (i + j + k); //メモして返す return dp[i][j][k] = res; } int main() { cin >> n; int one = 0; int two = 0; int three = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) one++; if (a == 2) two++; if (a == 3) three++; } memset(dp, -1.0, sizeof(dp)); cout << fixed << setprecision(10) << rec(one, two, three) << endl; return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 //なんで解けたか //何番目にあるかは対称性より関係ない //枚数が0-3だけなので状態がまとめられる // n枚で固定なので1個、2個、3個の枚数が決まればn-(i+j+k)で0個の皿の枚数が求まる //状態を3つ持つだけでいい300^3=9*10^6くらいで余裕 //遷移を書いたときに、遷移元と遷移先に同じ項が出てくる //どう解消するか→移項するだけ int n; double dp[310][310][310]; double rec(int i, int j, int k) { //メモってあればそれを使う //!=-1にするとdoubleのせいでバグる if (dp[i][j][k] >= 0.0) return dp[i][j][k]; //境界条件すべて0の状態から0枚にするのは自明に0枚必要 if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; // 1枚使った状態 値×確率を集める if (i > 0) res += rec(i - 1, j, k) * i; //残り1枚の皿が1枚減る if (j > 0) res += rec(i + 1, j - 1, k) * j; //残り2枚の皿が1枚減って、残り1枚になる if (k > 0) res += rec(i, j + 1, k - 1) * k; //残り3枚の皿が1枚減って、残り2枚の皿が1枚増える //+1にn/(i+j+k)をかけるとnになる。あとからまとめて(i+j+k)割るので、+n res += n; res *= 1.0 / (i + j + k); //メモして返す return dp[i][j][k] = res; } int main() { cin >> n; int one = 0; int two = 0; int three = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) one++; if (a == 2) two++; if (a == 3) three++; } memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << rec(one, two, three) << endl; return 0; }
[ "control_flow.branch.if.condition.change", "literal.number.change", "call.arguments.change" ]
978,014
978,015
u874996917
cpp
p03169
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 //なんで解けたか //何番目にあるかは対称性より関係ない //枚数が0-3だけなので状態がまとめられる // n枚で固定なので1個、2個、3個の枚数が決まればn-(i+j+k)で0個の皿の枚数が求まる //状態を3つ持つだけでいい300^3=9*10^6くらいで余裕 //遷移を書いたときに、遷移元と遷移先に同じ項が出てくる //どう解消するか→移項するだけ int n; double dp[310][310][310]; double rec(int i, int j, int k) { //メモってあればそれを使う if (dp[i][j][k] != -1.0) return dp[i][j][k]; //境界条件すべて0の状態から0枚にするのは自明に0枚必要 if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; // 1枚使った状態 値×確率を集める if (i > 0) res += rec(i - 1, j, k) * i; //残り1枚の皿が1枚減る if (j > 0) res += rec(i + 1, j - 1, k) * j; //残り2枚の皿が1枚減って、残り1枚になる if (k > 0) res += rec(i, j + 1, k - 1) * k; //残り3枚の皿が1枚減って、残り2枚の皿が1枚増える //+1にn/(i+j+k)をかけるとnになる。あとからまとめて(i+j+k)割るので、+n res += n; res *= 1.0 / (i + j + k); //メモして返す return dp[i][j][k] = res; } int main() { cin >> n; int one = 0; int two = 0; int three = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) one++; if (a == 2) two++; if (a == 3) three++; } memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << rec(one, two, three) << endl; return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 //なんで解けたか //何番目にあるかは対称性より関係ない //枚数が0-3だけなので状態がまとめられる // n枚で固定なので1個、2個、3個の枚数が決まればn-(i+j+k)で0個の皿の枚数が求まる //状態を3つ持つだけでいい300^3=9*10^6くらいで余裕 //遷移を書いたときに、遷移元と遷移先に同じ項が出てくる //どう解消するか→移項するだけ int n; double dp[310][310][310]; double rec(int i, int j, int k) { //メモってあればそれを使う //!=-1にするとdoubleのせいでバグる if (dp[i][j][k] >= 0.0) return dp[i][j][k]; //境界条件すべて0の状態から0枚にするのは自明に0枚必要 if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; // 1枚使った状態 値×確率を集める if (i > 0) res += rec(i - 1, j, k) * i; //残り1枚の皿が1枚減る if (j > 0) res += rec(i + 1, j - 1, k) * j; //残り2枚の皿が1枚減って、残り1枚になる if (k > 0) res += rec(i, j + 1, k - 1) * k; //残り3枚の皿が1枚減って、残り2枚の皿が1枚増える //+1にn/(i+j+k)をかけるとnになる。あとからまとめて(i+j+k)割るので、+n res += n; res *= 1.0 / (i + j + k); //メモして返す return dp[i][j][k] = res; } int main() { cin >> n; int one = 0; int two = 0; int three = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) one++; if (a == 2) two++; if (a == 3) three++; } memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << rec(one, two, three) << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
978,016
978,015
u874996917
cpp
p03169
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 //なんで解けたか //何番目にあるかは対称性より関係ない //枚数が0-3だけなので状態がまとめられる // n枚で固定なので1個、2個、3個の枚数が決まればn-(i+j+k)で0個の皿の枚数が求まる //状態を3つ持つだけでいい300^3=9*10^6くらいで余裕 //遷移を書いたときに、遷移元と遷移先に同じ項が出てくる //どう解消するか→移項するだけ int n; double dp[310][310][310]; double rec(int i, int j, int k) { //メモってあればそれを使う if (dp[i][j][k] != -1) return dp[i][j][k]; //境界条件すべて0の状態から0枚にするのは自明に0枚必要 if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; // 1枚使った状態 値×確率を集める if (i > 0) res += rec(i - 1, j, k) * i; //残り1枚の皿が1枚減る if (j > 0) res += rec(i + 1, j - 1, k) * j; //残り2枚の皿が1枚減って、残り1枚になる if (k > 0) res += rec(i, j + 1, k - 1) * k; //残り3枚の皿が1枚減って、残り2枚の皿が1枚増える //+1にn/(i+j+k)をかけるとnになる。あとからまとめて(i+j+k)割るので、+n res += n; res *= 1.0 / (i + j + k); //メモして返す return dp[i][j][k] = res; } int main() { cin >> n; int one = 0; int two = 0; int three = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) one++; if (a == 2) two++; if (a == 3) three++; } memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << rec(one, two, three) << endl; return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 //なんで解けたか //何番目にあるかは対称性より関係ない //枚数が0-3だけなので状態がまとめられる // n枚で固定なので1個、2個、3個の枚数が決まればn-(i+j+k)で0個の皿の枚数が求まる //状態を3つ持つだけでいい300^3=9*10^6くらいで余裕 //遷移を書いたときに、遷移元と遷移先に同じ項が出てくる //どう解消するか→移項するだけ int n; double dp[310][310][310]; double rec(int i, int j, int k) { //メモってあればそれを使う //!=-1にするとdoubleのせいでバグる if (dp[i][j][k] >= 0.0) return dp[i][j][k]; //境界条件すべて0の状態から0枚にするのは自明に0枚必要 if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; // 1枚使った状態 値×確率を集める if (i > 0) res += rec(i - 1, j, k) * i; //残り1枚の皿が1枚減る if (j > 0) res += rec(i + 1, j - 1, k) * j; //残り2枚の皿が1枚減って、残り1枚になる if (k > 0) res += rec(i, j + 1, k - 1) * k; //残り3枚の皿が1枚減って、残り2枚の皿が1枚増える //+1にn/(i+j+k)をかけるとnになる。あとからまとめて(i+j+k)割るので、+n res += n; res *= 1.0 / (i + j + k); //メモして返す return dp[i][j][k] = res; } int main() { cin >> n; int one = 0; int two = 0; int three = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) one++; if (a == 2) two++; if (a == 3) three++; } memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << rec(one, two, three) << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
978,017
978,015
u874996917
cpp
p03169
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 //なんで解けたか //何番目にあるかは対称性より関係ない //枚数が0-3だけなので状態がまとめられる // n枚で固定なので1個、2個、3個の枚数が決まればn-(i+j+k)で0個の皿の枚数が求まる //状態を3つ持つだけでいい300^3=9*10^6くらいで余裕 //遷移を書いたときに、遷移元と遷移先に同じ項が出てくる //どう解消するか→移項するだけ int n; double dp[310][310][310]; double rec(int i, int j, int k) { //メモってあればそれを使う if (dp[i][j][k] != -1) return dp[i][j][k]; //境界条件すべて0の状態から0枚にするのは自明に0枚必要 if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; // 1枚使った状態 値×確率を集める if (i > 0) res += rec(i - 1, j, k) * i; //残り1枚の皿が1枚減る if (j > 0) res += rec(i + 1, j - 1, k) * j; //残り2枚の皿が1枚減って、残り1枚になる if (k > 0) res += rec(i, j + 1, k - 1) * k; //残り3枚の皿が1枚減って、残り2枚の皿が1枚増える //+1にn/(i+j+k)をかけるとnになる。あとからまとめて(i+j+k)割るので、+n res += n; res *= 1.0 / (i + j + k); //メモして返す return dp[i][j][k] = res; } int main() { cin >> n; int one = 0; int two = 0; int three = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) one++; if (a == 2) two++; if (a == 3) three++; } memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << rec(one, two, three) << endl; return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 //なんで解けたか //何番目にあるかは対称性より関係ない //枚数が0-3だけなので状態がまとめられる // n枚で固定なので1個、2個、3個の枚数が決まればn-(i+j+k)で0個の皿の枚数が求まる //状態を3つ持つだけでいい300^3=9*10^6くらいで余裕 //遷移を書いたときに、遷移元と遷移先に同じ項が出てくる //どう解消するか→移項するだけ int n; double dp[310][310][310]; double rec(int i, int j, int k) { //メモってあればそれを使う if (dp[i][j][k] >= 0) return dp[i][j][k]; //境界条件すべて0の状態から0枚にするのは自明に0枚必要 if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; // 1枚使った状態 値×確率を集める if (i > 0) res += rec(i - 1, j, k) * i; //残り1枚の皿が1枚減る if (j > 0) res += rec(i + 1, j - 1, k) * j; //残り2枚の皿が1枚減って、残り1枚になる if (k > 0) res += rec(i, j + 1, k - 1) * k; //残り3枚の皿が1枚減って、残り2枚の皿が1枚増える //+1にn/(i+j+k)をかけるとnになる。あとからまとめて(i+j+k)割るので、+n res += n; res *= 1.0 / (i + j + k); //メモして返す return dp[i][j][k] = res; } int main() { cin >> n; int one = 0; int two = 0; int three = 0; for (int i = 0; i < n; i++) { int a; cin >> a; if (a == 1) one++; if (a == 2) two++; if (a == 3) three++; } memset(dp, -1, sizeof(dp)); cout << fixed << setprecision(10) << rec(one, two, three) << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
978,017
978,018
u874996917
cpp
p03169
#include <bits/stdc++.h> using namespace std; #define FastRead \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll unsigned long long int #define ld double #define FOR(i, a, n) for (int i = (a); i <= (n); ++i) #define RFOR(i, a, n) for (int i = (n); i >= (a); --i) #define FI(i, n) for (int i = 0; i < (n); ++i) #define ZERO(a) memset((a), 0, sizeof((a))) #define f first // #define s second #define pb push_back #define mk make_pair #define all(g) g.begin(), g.end() int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; } int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; } // #include <ext/pb_ds/assoc_container.hpp> // Common file // #include <ext/pb_ds/tree_policy.hpp> // Including // tree_order_statistics_node_updat using namespace __gnu_pbds; typedef tree<ll, // null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> // ordered_set; // I am questioning life and universe and // everything else after looking at this const ll MAXN = 305; ll arr[MAXN]; ld dp[MAXN][MAXN][MAXN]; ll n; ld rec(ll cnt1, ll cnt2, ll cnt3) { if (cnt1 < 0 || cnt2 < 0 || cnt3 < 0) return 0; if (cnt1 == 0 && cnt2 == 0 && cnt3 == 0) return 0; ld &ans = dp[cnt1][cnt2][cnt3]; if (ans != -1) return ans; ans = 1.0 + cnt1 * 1.0 * rec(cnt1 - 1, cnt2, cnt3) / n + cnt2 * 1.0 * rec(cnt1 + 1, cnt2 - 1, cnt3) / n + cnt3 * 1.0 * rec(cnt1, cnt2 + 1, cnt3 - 1) / n; ans = ans * n * 1.0 / (cnt1 + cnt2 + cnt3); return ans; } void solve() { cin >> n; FOR(i, 0, n) FOR(j, 0, n) FOR(k, 0, n) dp[i][j][k] = -1; ll cnt1 = 0, cnt2 = 0, cnt3 = 0; FOR(i, 1, n) { cin >> arr[i]; if (arr[i] == 1) cnt1++; else if (arr[i] == 2) cnt2++; else cnt3++; } ld ans = rec(cnt1, cnt2, cnt3); cout << fixed << setprecision(10) << ans << endl; } signed main() { ll t; t = 1; // cin>>t; FOR(tt, 1, t) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define FastRead \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long int #define ld double #define FOR(i, a, n) for (int i = (a); i <= (n); ++i) #define RFOR(i, a, n) for (int i = (n); i >= (a); --i) #define FI(i, n) for (int i = 0; i < (n); ++i) #define ZERO(a) memset((a), 0, sizeof((a))) #define f first // #define s second #define pb push_back #define mk make_pair #define all(g) g.begin(), g.end() int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; } int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; } // #include <ext/pb_ds/assoc_container.hpp> // Common file // #include <ext/pb_ds/tree_policy.hpp> // Including // tree_order_statistics_node_updat using namespace __gnu_pbds; typedef tree<ll, // null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> // ordered_set; // I am questioning life and universe and // everything else after looking at this const ll MAXN = 305; ll arr[MAXN]; ld dp[MAXN][MAXN][MAXN]; ll n; ld rec(ll cnt1, ll cnt2, ll cnt3) { if (cnt1 < 0 || cnt2 < 0 || cnt3 < 0) return 0; if (cnt1 == 0 && cnt2 == 0 && cnt3 == 0) return 0; ld &ans = dp[cnt1][cnt2][cnt3]; if (ans >= 0) return ans; ans = 1.0 + cnt1 * 1.0 * rec(cnt1 - 1, cnt2, cnt3) / n + cnt2 * 1.0 * rec(cnt1 + 1, cnt2 - 1, cnt3) / n + cnt3 * 1.0 * rec(cnt1, cnt2 + 1, cnt3 - 1) / n; ans = ans * n * 1.0 / (cnt1 + cnt2 + cnt3); return ans; } void solve() { cin >> n; FOR(i, 0, n) FOR(j, 0, n) FOR(k, 0, n) dp[i][j][k] = -1; ll cnt1 = 0, cnt2 = 0, cnt3 = 0; FOR(i, 1, n) { cin >> arr[i]; if (arr[i] == 1) cnt1++; else if (arr[i] == 2) cnt2++; else cnt3++; } ld ans = rec(cnt1, cnt2, cnt3); cout << fixed << setprecision(10) << ans << endl; } signed main() { ll t; t = 1; // cin>>t; FOR(tt, 1, t) { solve(); } }
[ "control_flow.branch.if.condition.change" ]
978,034
978,035
u612858131
cpp
p03169
#include <bits/stdc++.h> using namespace std; #define FastRead \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll unsigned long long int #define ld long double #define FOR(i, a, n) for (int i = (a); i <= (n); ++i) #define RFOR(i, a, n) for (int i = (n); i >= (a); --i) #define FI(i, n) for (int i = 0; i < (n); ++i) #define ZERO(a) memset((a), 0, sizeof((a))) #define f first // #define s second #define pb push_back #define mk make_pair #define all(g) g.begin(), g.end() int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; } int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; } // #include <ext/pb_ds/assoc_container.hpp> // Common file // #include <ext/pb_ds/tree_policy.hpp> // Including // tree_order_statistics_node_updat using namespace __gnu_pbds; typedef tree<ll, // null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> // ordered_set; // I am questioning life and universe and // everything else after looking at this const ll MAXN = 305; ll arr[MAXN]; ld dp[MAXN][MAXN][MAXN]; ll n; ld rec(ll cnt1, ll cnt2, ll cnt3) { if (cnt1 < 0 || cnt2 < 0 || cnt3 < 0) return 0; if (cnt1 == 0 && cnt2 == 0 && cnt3 == 0) return 0; ld &ans = dp[cnt1][cnt2][cnt3]; if (ans != -1) return ans; ans = 1.0 + cnt1 * 1.0 * rec(cnt1 - 1, cnt2, cnt3) / n + cnt2 * 1.0 * rec(cnt1 + 1, cnt2 - 1, cnt3) / n + cnt3 * 1.0 * rec(cnt1, cnt2 + 1, cnt3 - 1) / n; ans = ans * n * 1.0 / (cnt1 + cnt2 + cnt3); return ans; } void solve() { cin >> n; FOR(i, 0, n) FOR(j, 0, n) FOR(k, 0, n) dp[i][j][k] = -1; ll cnt1 = 0, cnt2 = 0, cnt3 = 0; FOR(i, 1, n) { cin >> arr[i]; if (arr[i] == 1) cnt1++; else if (arr[i] == 2) cnt2++; else cnt3++; } ld ans = rec(cnt1, cnt2, cnt3); cout << fixed << setprecision(10) << ans << endl; } signed main() { ll t; t = 1; // cin>>t; FOR(tt, 1, t) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define FastRead \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long int #define ld double #define FOR(i, a, n) for (int i = (a); i <= (n); ++i) #define RFOR(i, a, n) for (int i = (n); i >= (a); --i) #define FI(i, n) for (int i = 0; i < (n); ++i) #define ZERO(a) memset((a), 0, sizeof((a))) #define f first // #define s second #define pb push_back #define mk make_pair #define all(g) g.begin(), g.end() int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; } int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; } // #include <ext/pb_ds/assoc_container.hpp> // Common file // #include <ext/pb_ds/tree_policy.hpp> // Including // tree_order_statistics_node_updat using namespace __gnu_pbds; typedef tree<ll, // null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> // ordered_set; // I am questioning life and universe and // everything else after looking at this const ll MAXN = 305; ll arr[MAXN]; ld dp[MAXN][MAXN][MAXN]; ll n; ld rec(ll cnt1, ll cnt2, ll cnt3) { if (cnt1 < 0 || cnt2 < 0 || cnt3 < 0) return 0; if (cnt1 == 0 && cnt2 == 0 && cnt3 == 0) return 0; ld &ans = dp[cnt1][cnt2][cnt3]; if (ans >= 0) return ans; ans = 1.0 + cnt1 * 1.0 * rec(cnt1 - 1, cnt2, cnt3) / n + cnt2 * 1.0 * rec(cnt1 + 1, cnt2 - 1, cnt3) / n + cnt3 * 1.0 * rec(cnt1, cnt2 + 1, cnt3 - 1) / n; ans = ans * n * 1.0 / (cnt1 + cnt2 + cnt3); return ans; } void solve() { cin >> n; FOR(i, 0, n) FOR(j, 0, n) FOR(k, 0, n) dp[i][j][k] = -1; ll cnt1 = 0, cnt2 = 0, cnt3 = 0; FOR(i, 1, n) { cin >> arr[i]; if (arr[i] == 1) cnt1++; else if (arr[i] == 2) cnt2++; else cnt3++; } ld ans = rec(cnt1, cnt2, cnt3); cout << fixed << setprecision(10) << ans << endl; } signed main() { ll t; t = 1; // cin>>t; FOR(tt, 1, t) { solve(); } }
[ "control_flow.branch.if.condition.change" ]
978,036
978,035
u612858131
cpp
p03169
// Daritys Morgho ban Rovegrie // Math = ♥ // Sometimes it is people that no one imagines anything of who do things that no // one can imagine After all this time? Always #include <bits/stdc++.h> // uncomment before submission //#include <ext/pb_ds/assoc_container.hpp> // uncomment before //submission //#include <ext/pb_ds/tree_policy.hpp> // uncomment before //submission // using namespace __gnu_pbds; // uncomment before // submission using namespace std; //<---------------------------------------------------Template-----------------------------------------------------------> #define int long long #define ll long long #define ld long double const int INF = 1e15 + 7; const int MAX = 310; const int MOD = 1e9 + 7; typedef pair<ll, ll> ii; typedef vector<ll> vi; // Vector of long long typedef vector<vi> vvi; // Vector of vi typedef vector<ii> vii; // Vector of pairs typedef vector<vii> vvii; // Vector of Vector of pairs typedef vector<bool> vb; // Vector of bool #define pq \ priority_queue // Max heap (To convert to min heap, use negative sign before // every value) #define ff first // For pairs #define ss second // For pairs #define pb push_back // Push back to vector #define mp make_pair // Makes pairs to be stored as pair #define all(c) (c).begin(), (c).end() // Mainly used by me in sorting #define run(x, c) \ (x) = (c).begin(); \ (x) != (c).end(); \ (x)++ // Mainly used by me for range based loops // ordered_set adds two new functions to set - (set).find_by_order([kth element // based on zero indexing]) and order_of_key() order_of_key returns number of // elements less that parameter. If element exists, that order is its index #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> //<-----------------------------------------------------------------------------------------------------------------------> vector<vector<vector<ld>>> f(310, vector<vector<ld>>(310, vector<ld>(310, -10))); int n = 0; ld solve(int i, int j, int k) { if (i == 0 && j == 0 && k == 0) return 0; if (i < 0 || j < 0 || k < 0) return 0; else if (f[i][j][k] >= 0) return f[i][j][k]; f[i][j][k] = (((ld)n) / ((ld)(i + j + k))) + (((ld)i) / ((ld)(i + j + k))) * (solve(i - 1, j, k)) + (((ld)j) / ((ld)(i + j + k))) * (solve(i + 1, j - 1, k)) + (((ld)n) / ((ld)(i + j + k))) * (solve(i, j + 1, k - 1)); return f[i][j][k]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; int x = 0, y = 0, z = 0, a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) x++; else if (a[i] == 2) y++; else z++; } ld ans = solve(x, y, z); printf("%0.9Lf", ans); return 0; }
// Daritys Morgho ban Rovegrie // Math = ♥ // Sometimes it is people that no one imagines anything of who do things that no // one can imagine After all this time? Always #include <bits/stdc++.h> // uncomment before submission //#include <ext/pb_ds/assoc_container.hpp> // uncomment before //submission //#include <ext/pb_ds/tree_policy.hpp> // uncomment before //submission // using namespace __gnu_pbds; // uncomment before // submission using namespace std; //<---------------------------------------------------Template-----------------------------------------------------------> #define int long long #define ll long long #define ld long double const int INF = 1e15 + 7; const int MAX = 310; const int MOD = 1e9 + 7; typedef pair<ll, ll> ii; typedef vector<ll> vi; // Vector of long long typedef vector<vi> vvi; // Vector of vi typedef vector<ii> vii; // Vector of pairs typedef vector<vii> vvii; // Vector of Vector of pairs typedef vector<bool> vb; // Vector of bool #define pq \ priority_queue // Max heap (To convert to min heap, use negative sign before // every value) #define ff first // For pairs #define ss second // For pairs #define pb push_back // Push back to vector #define mp make_pair // Makes pairs to be stored as pair #define all(c) (c).begin(), (c).end() // Mainly used by me in sorting #define run(x, c) \ (x) = (c).begin(); \ (x) != (c).end(); \ (x)++ // Mainly used by me for range based loops // ordered_set adds two new functions to set - (set).find_by_order([kth element // based on zero indexing]) and order_of_key() order_of_key returns number of // elements less that parameter. If element exists, that order is its index #define ordered_set \ tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> //<-----------------------------------------------------------------------------------------------------------------------> vector<vector<vector<ld>>> f(310, vector<vector<ld>>(310, vector<ld>(310, -10))); int n = 0; ld solve(int i, int j, int k) { if (i == 0 && j == 0 && k == 0) return 0; if (i < 0 || j < 0 || k < 0) return 0; else if (f[i][j][k] >= 0) return f[i][j][k]; f[i][j][k] = (((ld)n) / ((ld)(i + j + k))) + (((ld)i) / ((ld)(i + j + k))) * (solve(i - 1, j, k)) + (((ld)j) / ((ld)(i + j + k))) * (solve(i + 1, j - 1, k)) + (((ld)k) / ((ld)(i + j + k))) * (solve(i, j + 1, k - 1)); return f[i][j][k]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; int x = 0, y = 0, z = 0, a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) x++; else if (a[i] == 2) y++; else z++; } ld ans = solve(x, y, z); printf("%0.9Lf", ans); return 0; }
[ "assignment.value.change", "identifier.change", "expression.operation.binary.change" ]
978,055
978,056
u299029266
cpp
p03169
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iostream> #include <string> #include <unordered_map> #include <unordered_set> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORR(i, a, b) for (ll i = (a); i <= (b); i++) #define repR(i, n) for (ll i = n; i >= 0; i--) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define F first #define S second #define pb push_back #define pu push #define COUT(x) cout << (x) << endl #define PQ priority_queue<ll> #define PQR priority_queue<ll, vector<ll>, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define mp make_pair #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define sz(x) (ll)(x).size() typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll MOD = 1000000007LL; const ll INF = 1LL << 60; using vll = vector<ll>; using vb = vector<bool>; using vvb = vector<vb>; using vvll = vector<vll>; using vstr = vector<string>; using pll = pair<ll, ll>; using vc = vector<char>; using vvc = vector<vc>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; ll n; vector<vector<vector<double>>> dp(310, vector<vector<double>>(310, vector<double>(310, -1.0))); double rec(ll i, ll j, ll k) { if (dp[i][j][k] >= 0) return dp[i][j][k]; if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; if (i > 0) res += rec(i - 1, j, k) * i; if (j > 0) res += rec(i + 1, j - 1, k) * j; if (k > 0) res += rec(i, j + 1, k - 1) * k; res += (double)n; res *= 1.0 / (i + j + k); return dp[i][j][k] = res; } int main() { cout << fixed << setprecision(10); cin >> n; ll i = 0; ll j = 0; ll k = 0; rep(i, n) { ll a; cin >> a; if (a == 1) i++; else if (a == 2) j++; else k++; } COUT(rec(i, j, k)); }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iostream> #include <string> #include <unordered_map> #include <unordered_set> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORR(i, a, b) for (ll i = (a); i <= (b); i++) #define repR(i, n) for (ll i = n; i >= 0; i--) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define F first #define S second #define pb push_back #define pu push #define COUT(x) cout << (x) << endl #define PQ priority_queue<ll> #define PQR priority_queue<ll, vector<ll>, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define mp make_pair #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define sz(x) (ll)(x).size() typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll MOD = 1000000007LL; const ll INF = 1LL << 60; using vll = vector<ll>; using vb = vector<bool>; using vvb = vector<vb>; using vvll = vector<vll>; using vstr = vector<string>; using pll = pair<ll, ll>; using vc = vector<char>; using vvc = vector<vc>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; ll n; vector<vector<vector<double>>> dp(310, vector<vector<double>>(310, vector<double>(310, -1.0))); double rec(ll i, ll j, ll k) { if (dp[i][j][k] >= 0) return dp[i][j][k]; if (i == 0 && j == 0 && k == 0) return 0.0; double res = 0.0; if (i > 0) res += rec(i - 1, j, k) * i; if (j > 0) res += rec(i + 1, j - 1, k) * j; if (k > 0) res += rec(i, j + 1, k - 1) * k; res += (double)n; res *= 1.0 / (i + j + k); return dp[i][j][k] = res; } int main() { cout << fixed << setprecision(10); cin >> n; ll i = 0; ll j = 0; ll k = 0; rep(o, n) { ll a; cin >> a; if (a == 1) i++; else if (a == 2) j++; else k++; } COUT(rec(i, j, k)); }
[]
978,068
978,069
u103850114
cpp
p03169
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdlib.h> #include <vector> using namespace std; int arr[4], n; double dp[305][305][305]; double dfs(int a, int b, int c) { if (a == 0 && b == 0 && c == 0) return 0; if (dp[a][b][c] > 0) return dp[a][b][c]; double ans = 1.0 * n / (a + b + c); if (a) ans += (1.0 * a / (a + b + c)) * dfs(a - 1, b, c); if (b) ans += (1.0 * b / (a + b + c)) * dfs(a + 1, b - 1, c); if (c) ans += (1.0 * c / (a + b + c)) * dfs(a, b + 1, c - 1); return dp[a][b][c] = ans; } int main() { int d; cin >> d; for (int i = 1; i <= n; ++i) { cin >> d; arr[d]++; } printf("%.10f\n", dfs(arr[1], arr[2], arr[3])); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdlib.h> #include <vector> using namespace std; int arr[4], n; double dp[305][305][305]; double dfs(int a, int b, int c) { if (a == 0 && b == 0 && c == 0) return 0; if (dp[a][b][c] > 0) return dp[a][b][c]; double ans = 1.0 * n / (a + b + c); if (a) ans += (1.0 * a / (a + b + c)) * dfs(a - 1, b, c); if (b) ans += (1.0 * b / (a + b + c)) * dfs(a + 1, b - 1, c); if (c) ans += (1.0 * c / (a + b + c)) * dfs(a, b + 1, c - 1); return dp[a][b][c] = ans; } int main() { int d; cin >> n; for (int i = 1; i <= n; ++i) { cin >> d; arr[d]++; } printf("%.10f\n", dfs(arr[1], arr[2], arr[3])); // cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << // endl; return 0; }
[ "identifier.change", "expression.operation.binary.change" ]
978,070
978,071
u198862456
cpp
p03169
#include <bits/stdc++.h> #define XD (a + b + c) using namespace std; const int maxn = 302; bool bylo[maxn][maxn][maxn]; double dp[maxn][maxn][maxn]; int n; double calc(int a, int b, int c) { if (a == -1 || b == -1 || c == -1) return 0; if (a == 0 && b == 0 && c == 0) return 0; if (bylo[a][b][c]) return dp[a][b][c]; bylo[a][b][c] = true; dp[a][b][c] = ((double)n / XD) + calc(a - 1, b, c) * ((double)a / XD) + calc(a + 1, b - 1, c) * ((double)b / XD) + calc(a, b + 1, c - 1) * ((double)c / XD); return dp[a][b][c]; } int main() { scanf("%d", &n); int a = 0, b = 0, c = 0; for (int i = 1; i <= n; i++) { int p; scanf("%d", &p); if (p == 1) ++a; if (p == 2) ++b; if (c == 3) ++c; } printf("%.10lf", calc(a, b, c)); }
#include <bits/stdc++.h> #define XD (a + b + c) using namespace std; const int maxn = 302; bool bylo[maxn][maxn][maxn]; double dp[maxn][maxn][maxn]; int n; double calc(int a, int b, int c) { // printf("a=%d b=%d c=%d\n",a,b,c); if (a == -1 || b == -1 || c == -1) return 0; if (a == 0 && b == 0 && c == 0) return 0; if (bylo[a][b][c]) return dp[a][b][c]; bylo[a][b][c] = true; dp[a][b][c] = ((double)n / XD) + calc(a - 1, b, c) * ((double)a / XD) + calc(a + 1, b - 1, c) * ((double)b / XD) + calc(a, b + 1, c - 1) * ((double)c / XD); return dp[a][b][c]; } int main() { scanf("%d", &n); int a = 0, b = 0, c = 0; for (int i = 1; i <= n; i++) { int p; scanf("%d", &p); if (p == 1) ++a; if (p == 2) ++b; if (p == 3) ++c; } // printf("a=%d b=%d c=%d\n",a,b,c); printf("%.10lf", calc(a, b, c)); }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
978,081
978,082
u376648895
cpp
p03169
#include <bits/stdc++.h> #define XD (a + b + c) using namespace std; const int maxn = 302; bool bylo[maxn][maxn][maxn]; double dp[maxn][maxn][maxn]; int n; double calc(int a, int b, int c) { if (a == -1 || b == -1 || c == -1) return 0; if (a == 0 && b == 0 && c == 0) return 0; if (bylo[a][b][c]) return dp[a][b][c]; bylo[a][b][c] = true; dp[a][b][c] = ((double)n / XD) + calc(a - 1, b, c) * ((double)a / XD) + calc(a + 1, b - 1, c) * ((double)b / XD) + calc(a, b + 1, c - 1) * ((double)c / XD); return dp[a][b][c]; } int main() { scanf("%d", &n); int a = 0, b = 0, c = 0; for (int i = 1; i <= n; i++) { int p; scanf("%d", &p); if (p == 1) ++a; if (p == 2) ++b; if (c == 3) ++c; } printf("%lf", calc(a, b, c)); }
#include <bits/stdc++.h> #define XD (a + b + c) using namespace std; const int maxn = 302; bool bylo[maxn][maxn][maxn]; double dp[maxn][maxn][maxn]; int n; double calc(int a, int b, int c) { // printf("a=%d b=%d c=%d\n",a,b,c); if (a == -1 || b == -1 || c == -1) return 0; if (a == 0 && b == 0 && c == 0) return 0; if (bylo[a][b][c]) return dp[a][b][c]; bylo[a][b][c] = true; dp[a][b][c] = ((double)n / XD) + calc(a - 1, b, c) * ((double)a / XD) + calc(a + 1, b - 1, c) * ((double)b / XD) + calc(a, b + 1, c - 1) * ((double)c / XD); return dp[a][b][c]; } int main() { scanf("%d", &n); int a = 0, b = 0, c = 0; for (int i = 1; i <= n; i++) { int p; scanf("%d", &p); if (p == 1) ++a; if (p == 2) ++b; if (p == 3) ++c; } // printf("a=%d b=%d c=%d\n",a,b,c); printf("%.10lf", calc(a, b, c)); }
[ "identifier.change", "control_flow.branch.if.condition.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
978,083
978,082
u376648895
cpp
p03169
#include <iomanip> #include <iostream> using namespace std; double solver(int i, int j, int k, double ***dp, int n) { if (dp[i][j][k] >= 0) return dp[i][j][k]; if (i == 0 and j == 0 and k == 0) return 0; double ret = 0.0; if (i > 0) ret += solver(i - 1, j, k, dp, n) * i; if (j > 0 and i < n) ret += solver(i + 1, j - 1, k, dp, n) * j; if (k > 0 and j < n) ret += solver(i, j + 1, k - 1, dp, n) * k; ret += static_cast<double>(n); ret *= 1.0 / (i + j + k); return dp[i][j][k] = ret; } int main(int argc, char const *argv[]) { int n; cin >> n; int a[3] = {0}; for (int i = 0; i < n; i++) { int temp; cin >> temp; a[(temp + 1) % 3]++; } double ***dp = new double **[n + 1]; for (int i = 0; i <= n; i++) dp[i] = new double *[n + 1]; for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = new double[n + 1]; for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) for (int k = 0; k <= n; k++) dp[i][j][k] = -1.0; dp[0][0][0] = 0.0; double ans = solver(a[0], a[1], a[2], dp, n); cout << setprecision(10) << ans << endl; for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) delete[] dp[i][j]; for (int i = 0; i <= n; i++) delete[] dp[i]; delete[] dp; return 0; }
#include <iomanip> #include <iostream> using namespace std; double solver(int i, int j, int k, double ***dp, int n) { if (dp[i][j][k] >= 0) return dp[i][j][k]; if (i == 0 and j == 0 and k == 0) return 0; double ret = 0.0; if (i > 0) ret += solver(i - 1, j, k, dp, n) * i; if (j > 0 and i < n) ret += solver(i + 1, j - 1, k, dp, n) * j; if (k > 0 and j < n) ret += solver(i, j + 1, k - 1, dp, n) * k; ret += static_cast<double>(n); ret *= 1.0 / (i + j + k); return dp[i][j][k] = ret; } int main(int argc, char const *argv[]) { int n; cin >> n; int a[3] = {0}; for (int i = 0; i < n; i++) { int temp; cin >> temp; a[(temp - 1) % 3]++; } double ***dp = new double **[n + 1]; for (int i = 0; i <= n; i++) dp[i] = new double *[n + 1]; for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = new double[n + 1]; for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) for (int k = 0; k <= n; k++) dp[i][j][k] = -1.0; dp[0][0][0] = 0.0; double ans = solver(a[0], a[1], a[2], dp, n); cout << setprecision(10) << ans << endl; for (int i = 0; i <= n; i++) for (int j = 0; j <= n; j++) delete[] dp[i][j]; for (int i = 0; i <= n; i++) delete[] dp[i]; delete[] dp; return 0; }
[ "misc.opposites", "expression.operator.arithmetic.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
978,094
978,095
u534223360
cpp
p03169
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> s(3); for (int i = 0; i < n; i++) { int a; cin >> a; s.at(a - 1)++; } vector<vector<vector<double>>> dp( n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1))); for (int k = 0; k <= n; k++) { for (int j = 0; j <= n; j++) { for (int i = 0; i <= n; i++) { if (i == 0 && j == 0 && k == 0) continue; if (i) dp[i][j][k] += i * dp[i - 1][j][k] / (i + j + k); if (j) dp[i][j][k] += j * dp[i + 1][j - 1][k] / (i + j + k); if (k) dp[i][j][k] += k * dp[i][j + 1][k - 1] / (i + j + k); dp[i][j][k] += 1.0 * n / (i + j + k); } } } cout << setprecision(17) << dp[s.at(0)][s.at(1)][s.at(2)] << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> s(3); for (int i = 0; i < n; i++) { int a; cin >> a; s.at(a - 1)++; } vector<vector<vector<double>>> dp( n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1))); for (int k = 0; k <= n; k++) { for (int j = 0; j <= n - k; j++) { for (int i = 0; i <= n - k - j; i++) { if (i == 0 && j == 0 && k == 0) continue; if (i) dp[i][j][k] += i * dp[i - 1][j][k] / (i + j + k); if (j) dp[i][j][k] += j * dp[i + 1][j - 1][k] / (i + j + k); if (k) dp[i][j][k] += k * dp[i][j + 1][k - 1] / (i + j + k); dp[i][j][k] += 1.0 * n / (i + j + k); } } } cout << setprecision(17) << dp[s.at(0)][s.at(1)][s.at(2)] << endl; }
[ "control_flow.loop.for.condition.change" ]
978,100
978,101
u697658632
cpp
p03169
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int n; double memo[901][601][301]; double dfs(int a, int b, int c) { if (a + b + c == 0) return 0; if (memo[a][b][c] != -1) return memo[a][b][c]; double r = 1.0 * (n - a - b - c) / n, sum = 1; if (a > 0) sum += dfs(a - 1, b, c) * a / n; else r += 1.0 * a / n; if (b > 0) sum += dfs(a + 1, b - 1, c) * b / n; else r += 1.0 * b / n; if (c > 0) sum += dfs(a, b + 1, c - 1) * c / n; else r += 1.0 * c / n; return memo[a][b][c] = sum / (1 - r); } int main() { int cnt[3] = {}; scanf("%d", &n); rep(i, n) { int a; scanf("%d", &a); cnt[a - 1]++; } rep(i, 3 * n + 1) rep(j, 2 * n + 1) rep(k, n + 1) memo[i][j][k] = -1; printf("%.9f\n", dfs(cnt[0], cnt[1], cnt[2])); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int n; double memo[301][301][301]; double dfs(int a, int b, int c) { if (a + b + c == 0) return 0; if (memo[a][b][c] != -1) return memo[a][b][c]; double r = 1.0 * (n - a - b - c) / n, sum = 1; if (a > 0) sum += dfs(a - 1, b, c) * a / n; else r += 1.0 * a / n; if (b > 0) sum += dfs(a + 1, b - 1, c) * b / n; else r += 1.0 * b / n; if (c > 0) sum += dfs(a, b + 1, c - 1) * c / n; else r += 1.0 * c / n; return memo[a][b][c] = sum / (1 - r); } int main() { int cnt[3] = {}; scanf("%d", &n); rep(i, n) { int a; scanf("%d", &a); cnt[a - 1]++; } rep(i, n + 1) rep(j, n + 1) rep(k, n + 1) memo[i][j][k] = -1; printf("%.9f\n", dfs(cnt[0], cnt[1], cnt[2])); return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "expression.operation.binary.remove" ]
978,102
978,103
u781095600
cpp