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 |
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_i
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define fs second
#define lb lower_bound
#define ub upper_bound
#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vb vector<bool>
#define si set<int>
#define mii map<int, int>
#define mci map<char, int>
#define md 1000000007
#define pb push_back
#define eb emplace_back
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define qw1(x) cerr << #x << ": " << x << " " << endl
#define qw2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define qw3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define qw4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define f(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define rl(i, a, b) for (int i = (int)a; i >= (int)b; i--)
#define all(x) x.begin(), x.end()
#define endl '\n'
void printv(vector<int> v) {
for (int i = 0; i < v.size(); i++)
cout << v[i] << ' ';
cout << endl;
}
int bem(int m, int n, int mod) {
int res = 1;
while (n) {
if (n % 2 != 0) {
res *= m;
res %= mod;
}
m *= m;
m %= mod;
n /= 2;
}
return res;
}
int be(int a, int b) {
int res = 1;
while (b) {
if (b % 2 != 0)
res *= a;
a *= a;
b /= 2;
}
return res;
}
void sieve(int n, vb &prime) {
prime[0] = false;
prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (prime[i] == true) {
for (int j = i * i; j <= n; j += i)
prime[j] = false;
}
}
}
vector<long double> p;
vector<vector<long double>> dp;
void solve() {
int n;
cin >> n;
p.resize(n + 1);
f(i, 1, n) cin >> p[i];
// f(i,1, n) cout<<p[i]<<' '; cout<<endl;
dp.resize(n + 1, vector<long double>(n + 1, 1.0 * 0));
dp[1][0] = 1 - p[1];
f(i, 2, n) dp[i][0] = dp[i - 1][0] * (1 - p[i]);
// f(i,1, n) cout<<dp[i][0]<<' '; cout<<endl;
dp[1][1] = p[1];
f(i, 2, n) dp[i][i] = dp[i - 1][i - 1] * p[i];
f(i, 2, n) f(j, 1, i - 1) dp[i][j] =
dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
long double ans;
// f(i,1, n) cout<<dp[n][i]<<' '; cout<<endl;
f(i, ((n + 1) / 2), n) { ans += dp[n][i]; } // qw3(i, dp[n][i], ans);}
// f(i, 1, n) { f(j, 1, n) cout<<dp[i][j]<<" "; cout<<endl;}
cout << fixed << setprecision(12) << ans << endl;
}
int32_t main() {
// fio
int t = 1;
// cin>>t;
while (t--) {
solve();
}
}
|
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_i
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define fs second
#define lb lower_bound
#define ub upper_bound
#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vb vector<bool>
#define si set<int>
#define mii map<int, int>
#define mci map<char, int>
#define md 1000000007
#define pb push_back
#define eb emplace_back
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define qw1(x) cerr << #x << ": " << x << " " << endl
#define qw2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define qw3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define qw4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define f(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define rl(i, a, b) for (int i = (int)a; i >= (int)b; i--)
#define all(x) x.begin(), x.end()
#define endl '\n'
void printv(vector<int> v) {
for (int i = 0; i < v.size(); i++)
cout << v[i] << ' ';
cout << endl;
}
int bem(int m, int n, int mod) {
int res = 1;
while (n) {
if (n % 2 != 0) {
res *= m;
res %= mod;
}
m *= m;
m %= mod;
n /= 2;
}
return res;
}
int be(int a, int b) {
int res = 1;
while (b) {
if (b % 2 != 0)
res *= a;
a *= a;
b /= 2;
}
return res;
}
void sieve(int n, vb &prime) {
prime[0] = false;
prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (prime[i] == true) {
for (int j = i * i; j <= n; j += i)
prime[j] = false;
}
}
}
vector<double> p;
vector<vector<double>> dp;
void solve() {
int n;
cin >> n;
p.resize(n + 1);
f(i, 1, n) cin >> p[i];
// f(i,1, n) cout<<p[i]<<' '; cout<<endl;
dp.resize(n + 1, vector<double>(n + 1, 1.0 * 0));
dp[1][0] = 1 - p[1];
f(i, 2, n) dp[i][0] = dp[i - 1][0] * (1 - p[i]);
// f(i,1, n) cout<<dp[i][0]<<' '; cout<<endl;
dp[1][1] = p[1];
f(i, 2, n) dp[i][i] = dp[i - 1][i - 1] * p[i];
f(i, 2, n) f(j, 1, i - 1) dp[i][j] =
dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
double ans;
// f(i,1, n) cout<<dp[n][i]<<' '; cout<<endl;
f(i, ((n + 1) / 2), n) { ans += dp[n][i]; } // qw3(i, dp[n][i], ans);}
// f(i, 1, n) { f(j, 1, n) cout<<dp[i][j]<<" "; cout<<endl;}
cout << fixed << setprecision(10) << ans << endl;
}
int32_t main() {
// fio
int t = 1;
// cin>>t;
while (t--) {
solve();
}
}
| [
"variable_declaration.type.narrow.change",
"literal.number.change",
"io.output.change"
] | 976,875 | 976,876 | u415771232 | cpp |
p03168 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define endl "\n"
#define loop(i, s, e) for (int i = s; i < e; i++)
#define int long long
#define vi vector<int>
#define S(v) sort(v.begin(), v.end())
#define RS(v) sort(v.rbegin(), v.rend())
#define R(v) reverse(v.begin(), v.end())
#define mxpq(T) priority_queue<T>
#define mnpq(T) priority_queue<T, vector<T>, greater<T>>
#define prv(v) \
for (auto &x : v) \
cout << x << " ";
#define piirv(v) \
for (auto &x : v) \
cout << x.ff << " " << x.ss << endl;
#define prvv(v) \
for (auto &x : v) \
for (auto &y : x.ss) \
cout << y << " ";
#define mp make_pair
#define pii pair<int, int>
#define mset(a, f) memset(a, f, sizeof(a))
#define pb push_back
#define inf INT_MAX
#define INF LLONG_MAX
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
oset;
const int N = 2e6 + 6;
const int M = 1e9 + 7;
long double A[N];
long double dp[3003][3003];
int n, m;
long double alpha(int i, int cnt) {
if (i == n) {
if (cnt > (n - 1) / 2)
return (1.0);
return 0.0;
}
long double &abs = dp[i][cnt];
if (abs != -1)
return abs;
long double a1 = 0, a2 = 0;
a1 = (1.0) * (1.0 - A[i]) * alpha(i + 1, cnt);
a2 = (1.0) * (A[i]) * alpha(i + 1, cnt + 1);
return abs = (a1 + a2);
}
void solve() {
cin >> n;
loop(i, 0, n) cin >> A[i];
loop(i, 0, n) loop(j, 0, n) dp[i][j] = (1.0) * (-1);
long double ans = alpha(0, 0);
cout << ans << endl;
}
int32_t main() {
cout << fixed << setprecision(2);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
solve();
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define endl "\n"
#define loop(i, s, e) for (int i = s; i < e; i++)
#define int long long
#define vi vector<int>
#define S(v) sort(v.begin(), v.end())
#define RS(v) sort(v.rbegin(), v.rend())
#define R(v) reverse(v.begin(), v.end())
#define mxpq(T) priority_queue<T>
#define mnpq(T) priority_queue<T, vector<T>, greater<T>>
#define prv(v) \
for (auto &x : v) \
cout << x << " ";
#define piirv(v) \
for (auto &x : v) \
cout << x.ff << " " << x.ss << endl;
#define prvv(v) \
for (auto &x : v) \
for (auto &y : x.ss) \
cout << y << " ";
#define mp make_pair
#define pii pair<int, int>
#define mset(a, f) memset(a, f, sizeof(a))
#define pb push_back
#define inf INT_MAX
#define INF LLONG_MAX
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
oset;
const int N = 2e6 + 6;
const int M = 1e9 + 7;
long double A[N];
long double dp[3003][3003];
int n, m;
long double alpha(int i, int cnt) {
if (i == n) {
if (cnt > (n - 1) / 2)
return (1.0);
return 0.0;
}
long double &abs = dp[i][cnt];
if (abs != -1)
return abs;
long double a1 = 0, a2 = 0;
a1 = (1.0) * (1.0 - A[i]) * alpha(i + 1, cnt);
a2 = (1.0) * (A[i]) * alpha(i + 1, cnt + 1);
return abs = (a1 + a2);
}
void solve() {
cin >> n;
loop(i, 0, n) cin >> A[i];
loop(i, 0, n) loop(j, 0, n) dp[i][j] = (1.0) * (-1);
long double ans = alpha(0, 0);
cout << ans << endl;
}
int32_t main() {
cout << fixed << setprecision(16);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
solve();
} | [
"literal.number.change",
"io.output.change"
] | 976,877 | 976,878 | u685006919 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double p[n + 1], q[n + 1];
for (int i = 1; i < n + 1; i++) {
cin >> p[i];
q[i] = 1 - p[i];
}
double dp[n + 1][n + 1];
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < n + 1; j++)
dp[i][j] = 0;
}
dp[0][0] = 1;
for (int i = 1; i < n + 1; i++) {
dp[i][0] = dp[i - 1][0] * q[i];
for (int j = 1; j < n + 1; j++) {
dp[i][j] = dp[i - 1][j] * q[i] + dp[i - 1][j - 1] * p[i];
}
}
double ans = 0;
for (int i = n; i < n + 1; i += 2) {
for (int j = i / 2 + 1; j < n + 1; j++)
ans += dp[i][j];
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double p[n + 1], q[n + 1];
for (int i = 1; i < n + 1; i++) {
cin >> p[i];
q[i] = 1 - p[i];
}
double dp[n + 1][n + 1];
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < n + 1; j++)
dp[i][j] = 0;
}
dp[0][0] = 1;
for (int i = 1; i < n + 1; i++) {
dp[i][0] = dp[i - 1][0] * q[i];
for (int j = 1; j < n + 1; j++) {
dp[i][j] = dp[i - 1][j] * q[i] + dp[i - 1][j - 1] * p[i];
}
}
double ans = 0;
for (int i = n; i < n + 1; i += 2) {
for (int j = i / 2 + 1; j < n + 1; j++)
ans += dp[i][j];
}
cout << setprecision(10) << ans;
} | [
"io.output.change"
] | 976,883 | 976,884 | u544893860 | cpp |
p03168 | #include <bits/stdc++.h>
#include <math.h>
#define N 100005
#define K 200005
#define MOD (int)1e9 + 7
#define ll long long int
using namespace std;
int main() {
int n;
cin >> n;
vector<double> dp(n + 1);
dp[0] = 1;
for (int i = 0; i < n; i++) {
double p;
cin >> p;
for (int j = i + 1; j >= 0; --j) {
dp[j] = (j == 0 ? 0 : dp[j - 1] * p) + dp[j] * (1 - p);
}
}
double ans = 0;
for (int i = 0; i <= n; i++) {
int t = n - i;
if (i > t)
ans += dp[i];
}
cout << setprecision(10) << fixed << 1.2;
} | #include <bits/stdc++.h>
#include <math.h>
#define N 100005
#define K 200005
#define MOD (int)1e9 + 7
#define ll long long int
using namespace std;
int main() {
int n;
cin >> n;
vector<double> dp(n + 1);
dp[0] = 1;
for (int i = 0; i < n; i++) {
double p;
cin >> p;
for (int j = i + 1; j >= 0; --j) {
dp[j] = (j == 0 ? 0 : dp[j - 1] * p) + dp[j] * (1 - p);
}
}
double ans = 0;
for (int i = 0; i <= n; i++) {
int t = n - i;
if (i > t)
ans += dp[i];
}
cout << setprecision(10) << fixed << ans;
} | [
"identifier.replace.add",
"literal.replace.remove",
"io.output.change"
] | 976,885 | 976,886 | u232473835 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int n;
cin >> n;
double a[n + 1];
a[0] = 0.0;
for (int i = 1; i <= n; i++)
cin >> a[i];
double dp[n + 1][n + 1];
memset(dp, 0, sizeof dp);
dp[0][0] = 1.0;
if (n == 1)
cout << a[1] << "\n";
else {
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (j == 0)
dp[i][j] = (1 - a[i]) * dp[i - 1][0];
else
dp[i][j] = dp[i - 1][j - 1] * a[i] + dp[i - 1][j] * (1 - a[i]);
}
}
double sum = 0;
for (int i = (n / 2) + 1; i <= n; i++)
sum += dp[n][i];
cout << sum << "\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int n;
cin >> n;
double a[n + 1];
a[0] = 0.0;
for (int i = 1; i <= n; i++)
cin >> a[i];
double dp[n + 1][n + 1];
memset(dp, 0, sizeof dp);
dp[0][0] = 1.0;
if (n == 1)
cout << a[1] << "\n";
else {
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
if (j == 0)
dp[i][j] = (1 - a[i]) * dp[i - 1][0];
else
dp[i][j] = dp[i - 1][j - 1] * a[i] + dp[i - 1][j] * (1 - a[i]);
}
}
double sum = 0;
for (int i = (n / 2) + 1; i <= n; i++)
sum += dp[n][i];
cout << setprecision(10) << sum << "\n";
}
return 0;
}
| [
"io.output.change"
] | 976,887 | 976,888 | u507549471 | cpp |
p03168 | #include <bits/stdc++.h>
#define next_permutation np // next_permutation(s.begin(),s.end())or arr,arr+3
// qsort( str, size, sizeof( str[0] ), compare ); for strings
// ceil/floor funtion
// upper_bound() return an iterator(important);
// map<pair<int, int>, int> vis;vos({0,0},1) used for positon ;//pair<int ,int
// >cur={0,0}; to get 3/2 ceil value ==2 use a=3,b=2;(b+a-1)/2
// a string can be converted into
// Note that the actual problem is to divide the string into two subsequences
// that both of them are non-decreasing. You can note that this is true because
// you cannot change the relative order of the elements colored in the same
// color, but you can write down subsequences of different colors in any order
// you want. agar 1111111 hogaya toh all increasing vector<pair<int, int>> a(n);
// for (int i = 0; i < n; ++i) {
// cin >> a[i].first >> a[i].second;
//}
// sort(a.begin(), a.end());
// prime factor
/*for(i=2;i*i<n&&k<2;i++)
{
if(n%i==0)
{
arr[k]=i;
k=k+1;
n=n/i;
}
}*/
/*
complexity ke maa ki chutttt
jo idea aa raha hai use implement kar
complexity ke maa ki chuut*/
// fast exponention a^10000=b//logn time/////
/*while(t--)
{
ll n,i,j,k=0,x,y,f=0;
cin >>n;
cin >>x;
for(i=1;i<n;i++)
{
cin >>y;
if(x*y>0)x=max(x,y);
else
{
k=k+x;
x=y;
}
}
k=k+x;
cout<<k<<endl;
*/
/* for(i=0;i<n/2;i++)
{
l=p[i].first+1;
r=p[i].second+k;
pref[l]=pref[l]+1;
pref[r+1]=pref[r+1]-1;
}
//Q is l r x
1 2 3
2 5 2
use this technique+prefix sum
for(i=2;i<=2*k;i++)
{
sum=sum+pref[i];
pref[i]=sum;
}
*/
/*
for(i=0;i<n;i++)
sort(v[i].begin(),v[i].end());
for(i=1;i<n;i++)
{
for(j=0;j<v[i].size();j++)
{
auto it=find(v[i-1].begin(),v[i-1].end(),v[i][j]);
if(it !=v[i-1].end())
{
ans++;
v[i-1].erase(it);
}
}
}
*/
#define ll long long
#define pb push_back
#define mp make_pair
/*
PPPPPPPRRRRRRRRRREEEEEEEEEFIXXXXXX SSSSSSSSSSSSUUUUUUUUUUMMMMMMMMMM*/
/*DIV 2 KE 2 MAX SAWAL KARNE hai
DIV 3 KE MAX 3 SAWAL KARNE HAI
LUNCHTIME/COOKOFF KE 2 MIN KARNE HAI
LONG KE 3 MIN KARNE HAI*/
/*SAWAL PADHE KE BAAD PHELE CONLUSION/FIGUREOUT KAR SAKTA NIKAL KE
N=1,N=2,N=0,YE NAHI KE SOLVE KARNE LAG JAY KYA KYA POSSIBLE VALUES HO SAKTE HAI
DIMAG LAGA
K*L KO MAX SE MIN TAK PAUCHANA HAI
AUR YE MAT SUCH KE NAHI HO SAKTA*/
ll M = 110000;
ll power(ll x, ll b) {
ll res = 1;
if (b == 0)
return 1;
while (b > 0) {
if (b % 2 != 0)
res = (res % M * x % M) % M;
b = b / 2;
x = (x % M * x % M) % M;
}
return (res + M % M);
}
int gcd(int a, int b) {
// Everything divides 0
if (a == 0)
return b;
if (b == 0)
return a;
// base case
if (a == b)
return a;
// a is greater
if (a > b)
return gcd(a - b, b);
return gcd(a, b - a);
}
/*for(i=0;i<n-1;i++)
{
if(arr[i]==arr[i+1])
{
c++;
}
else
{
v.pb(mp(arr[i],c));
c=1;
}
}
*/
ll fact[500005], inv[500005];
void pre() {
fact[0] = 1;
inv[0] = 1;
for (ll i = 1; i < 500005; i++) {
fact[i] = (fact[i - 1] * i) % M;
inv[i] = power(fact[i], M - 2);
}
}
ll C(ll n, ll r) {
ll ans = ((fact[n] * inv[r]) % M + M) % M; /////counting nCr aCb;
ans = ((ans * inv[n - r]) % M + M) % M;
return ans;
}
using namespace std;
vector<ll> g;
void bin(ll n) {
/* step 1 */
if (n > 1)
bin(n / 2);
/* step 2 */
g.pb(n % 2);
// cout << n % 2;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
double p[n + 1];
ll i;
for (i = 1; i <= n; i++) {
cin >> p[i];
}
double dp[n + 1][n + 1];
dp[0][0] = 1.0;
ll j;
for (i = 1; i <= n; i++)
dp[0][i] = 0.0;
for (i = 1; i <= n; i++) {
for (j = 0; j <= n; j++) {
if (j == 0) {
dp[i][j] = (1.0 - p[i]) * dp[i - 1][j];
} else {
dp[i][j] = (p[i]) * dp[i - 1][j - 1] + (1.0 - p[i]) * dp[i - 1][j];
}
}
}
double ans = 0.0;
for (i = n / 2 + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << ans;
} | #include <bits/stdc++.h>
#define next_permutation np // next_permutation(s.begin(),s.end())or arr,arr+3
// qsort( str, size, sizeof( str[0] ), compare ); for strings
// ceil/floor funtion
// upper_bound() return an iterator(important);
// map<pair<int, int>, int> vis;vos({0,0},1) used for positon ;//pair<int ,int
// >cur={0,0}; to get 3/2 ceil value ==2 use a=3,b=2;(b+a-1)/2
// a string can be converted into
// Note that the actual problem is to divide the string into two subsequences
// that both of them are non-decreasing. You can note that this is true because
// you cannot change the relative order of the elements colored in the same
// color, but you can write down subsequences of different colors in any order
// you want. agar 1111111 hogaya toh all increasing vector<pair<int, int>> a(n);
// for (int i = 0; i < n; ++i) {
// cin >> a[i].first >> a[i].second;
//}
// sort(a.begin(), a.end());
// prime factor
/*for(i=2;i*i<n&&k<2;i++)
{
if(n%i==0)
{
arr[k]=i;
k=k+1;
n=n/i;
}
}*/
/*
complexity ke maa ki chutttt
jo idea aa raha hai use implement kar
complexity ke maa ki chuut*/
// fast exponention a^10000=b//logn time/////
/*while(t--)
{
ll n,i,j,k=0,x,y,f=0;
cin >>n;
cin >>x;
for(i=1;i<n;i++)
{
cin >>y;
if(x*y>0)x=max(x,y);
else
{
k=k+x;
x=y;
}
}
k=k+x;
cout<<k<<endl;
*/
/* for(i=0;i<n/2;i++)
{
l=p[i].first+1;
r=p[i].second+k;
pref[l]=pref[l]+1;
pref[r+1]=pref[r+1]-1;
}
//Q is l r x
1 2 3
2 5 2
use this technique+prefix sum
for(i=2;i<=2*k;i++)
{
sum=sum+pref[i];
pref[i]=sum;
}
*/
/*
for(i=0;i<n;i++)
sort(v[i].begin(),v[i].end());
for(i=1;i<n;i++)
{
for(j=0;j<v[i].size();j++)
{
auto it=find(v[i-1].begin(),v[i-1].end(),v[i][j]);
if(it !=v[i-1].end())
{
ans++;
v[i-1].erase(it);
}
}
}
*/
#define ll long long
#define pb push_back
#define mp make_pair
/*
PPPPPPPRRRRRRRRRREEEEEEEEEFIXXXXXX SSSSSSSSSSSSUUUUUUUUUUMMMMMMMMMM*/
/*DIV 2 KE 2 MAX SAWAL KARNE hai
DIV 3 KE MAX 3 SAWAL KARNE HAI
LUNCHTIME/COOKOFF KE 2 MIN KARNE HAI
LONG KE 3 MIN KARNE HAI*/
/*SAWAL PADHE KE BAAD PHELE CONLUSION/FIGUREOUT KAR SAKTA NIKAL KE
N=1,N=2,N=0,YE NAHI KE SOLVE KARNE LAG JAY KYA KYA POSSIBLE VALUES HO SAKTE HAI
DIMAG LAGA
K*L KO MAX SE MIN TAK PAUCHANA HAI
AUR YE MAT SUCH KE NAHI HO SAKTA*/
ll M = 110000;
ll power(ll x, ll b) {
ll res = 1;
if (b == 0)
return 1;
while (b > 0) {
if (b % 2 != 0)
res = (res % M * x % M) % M;
b = b / 2;
x = (x % M * x % M) % M;
}
return (res + M % M);
}
int gcd(int a, int b) {
// Everything divides 0
if (a == 0)
return b;
if (b == 0)
return a;
// base case
if (a == b)
return a;
// a is greater
if (a > b)
return gcd(a - b, b);
return gcd(a, b - a);
}
/*for(i=0;i<n-1;i++)
{
if(arr[i]==arr[i+1])
{
c++;
}
else
{
v.pb(mp(arr[i],c));
c=1;
}
}
*/
ll fact[500005], inv[500005];
void pre() {
fact[0] = 1;
inv[0] = 1;
for (ll i = 1; i < 500005; i++) {
fact[i] = (fact[i - 1] * i) % M;
inv[i] = power(fact[i], M - 2);
}
}
ll C(ll n, ll r) {
ll ans = ((fact[n] * inv[r]) % M + M) % M; /////counting nCr aCb;
ans = ((ans * inv[n - r]) % M + M) % M;
return ans;
}
using namespace std;
vector<ll> g;
void bin(ll n) {
/* step 1 */
if (n > 1)
bin(n / 2);
/* step 2 */
g.pb(n % 2);
// cout << n % 2;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin >> n;
double p[n + 1];
ll i;
for (i = 1; i <= n; i++) {
cin >> p[i];
}
double dp[n + 1][n + 1];
dp[0][0] = 1.0;
ll j;
for (i = 1; i <= n; i++)
dp[0][i] = 0.0;
for (i = 1; i <= n; i++) {
for (j = 0; j <= n; j++) {
if (j == 0) {
dp[i][j] = (1.0 - p[i]) * dp[i - 1][j];
} else {
dp[i][j] = (p[i]) * dp[i - 1][j - 1] + (1.0 - p[i]) * dp[i - 1][j];
}
}
}
double ans = 0.0;
for (i = n / 2 + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << setprecision(10) << ans;
} | [
"io.output.change"
] | 976,891 | 976,892 | u898632998 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
typedef double ff;
#define ari \
for (int i = 1; i <= n; i++) \
cin >> p[i];
int n;
ff p[3002], dp[3002];
int main() {
cin >> n;
ari;
dp[0] = 1.000;
for (int i = 1; i <= n; i++) {
for (int j = i; j > 0; j--)
dp[j] = dp[j] * (1 - p[i]) + dp[j - 1] * p[i];
dp[0] *= (1 - p[i]);
}
for (int i = n / 2 + 1; i <= n; i++)
dp[n + 1] += dp[i];
cout << dp[n + 1] << endl;
return (0);
} | #include <bits/stdc++.h>
using namespace std;
typedef double ff;
#define ari \
for (int i = 1; i <= n; i++) \
cin >> p[i];
int n;
ff p[3002], dp[3002];
int main() {
cin >> n;
ari;
dp[0] = 1.000;
for (int i = 1; i <= n; i++) {
for (int j = i; j > 0; j--)
dp[j] = dp[j] * (1 - p[i]) + dp[j - 1] * p[i];
dp[0] *= (1 - p[i]);
}
for (int i = n / 2 + 1; i <= n; i++)
dp[n + 1] += dp[i];
cout << setprecision(11) << dp[n + 1] << endl;
return (0);
} | [
"io.output.change"
] | 976,895 | 976,896 | u681396939 | cpp |
p03168 | #include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 998244353
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define forn(i, n) for (int i = 1; i <= n; i++)
#define me0(x) memset(x, 0, sizeof(x))
#define me1(x) memset(x, -1, sizeof(x))
#define tests(x) \
int x; \
cin >> x; \
while (x--)
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> pbds;
const int N = 2e5 + 2;
void run() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int n;
double p[3003], dp[3003][3003];
void solve() {
cin >> n;
forn(i, n) cin >> p[i];
dp[1][0] = 1 - p[1];
dp[1][1] = p[1];
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= i; j++) {
dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
}
}
int heads = n / 2 + 1;
double ans = 0;
for (int i = heads; i <= n; i++) {
ans += dp[n][i];
}
cout << ps(ans, 10);
}
int32_t main() {
run();
solve();
return 0;
} | #include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 998244353
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define forn(i, n) for (int i = 1; i <= n; i++)
#define me0(x) memset(x, 0, sizeof(x))
#define me1(x) memset(x, -1, sizeof(x))
#define tests(x) \
int x; \
cin >> x; \
while (x--)
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> pbds;
const int N = 2e5 + 2;
void run() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int n;
double p[3003], dp[3003][3003];
void solve() {
cin >> n;
forn(i, n) cin >> p[i];
dp[1][0] = 1 - p[1];
dp[1][1] = p[1];
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= i; j++) {
dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
}
}
int heads = n / 2 + 1;
double ans = 0;
for (int i = heads; i <= n; i++) {
ans += dp[n][i];
}
cout << ps(ans, 10);
}
int32_t main() {
// run();
solve();
return 0;
} | [
"call.remove"
] | 976,905 | 976,906 | u996425102 | cpp |
p03168 | // coins problem
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#define ll long double
using namespace std;
void printmat(vector<vector<ll>> &dp, ll n) {
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= n; j++) {
cout << setw(6) << dp[i][j] << " ";
}
cout << endl;
}
}
int main() {
ll n;
cin >> n;
vector<ll> ph(n + 1, 0);
vector<vector<ll>> dp(n + 1);
for (ll i = 1; i <= n; i++)
cin >> ph[i];
for (ll i = 0; i <= n; i++) {
dp[i].resize(n + 1, 0);
}
// initializing dp
dp[1][1] = ph[1];
dp[0][1] = (1 - ph[1]);
for (ll i = 2; i <= n; i++) {
dp[i][i] = dp[i - 1][i - 1] * ph[i];
}
// filling 0th row
for (ll i = 2; i <= n; i++) {
dp[0][i] = dp[0][i - 1] * (1 - ph[i]);
}
// bottom up approach
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= n; j++) {
if (i == j)
continue;
dp[i][j] = ph[j] * dp[i - 1][j - 1] + (1 - ph[j]) * dp[i][j - 1];
}
}
ll st = ceil(n / 2);
ll tp = 0;
for (ll i = st; i <= n; i++) {
tp += dp[i][n];
}
cout << tp << endl;
// printmat(dp,n);
return 0;
}
| // coins problem
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#define ll long double
using namespace std;
void printmat(vector<vector<ll>> &dp, ll n) {
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= n; j++) {
cout << setw(6) << dp[i][j] << " ";
}
cout << endl;
}
}
int main() {
ll n;
cin >> n;
vector<ll> ph(n + 1, 0);
vector<vector<ll>> dp(n + 1);
for (ll i = 1; i <= n; i++)
cin >> ph[i];
for (ll i = 0; i <= n; i++) {
dp[i].resize(n + 1, 0);
}
// initializing dp
dp[1][1] = ph[1];
dp[0][1] = (1 - ph[1]);
for (ll i = 2; i <= n; i++) {
dp[i][i] = dp[i - 1][i - 1] * ph[i];
}
// filling 0th row
for (ll i = 2; i <= n; i++) {
dp[0][i] = dp[0][i - 1] * (1 - ph[i]);
}
// bottom up approach
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= n; j++) {
if (i == j)
continue;
dp[i][j] = ph[j] * dp[i - 1][j - 1] + (1 - ph[j]) * dp[i][j - 1];
}
}
ll st = ceil(n / 2);
ll tp = 0;
for (ll i = st; i <= n; i++) {
tp += dp[i][n];
}
cout << setprecision(9) << tp << endl;
// printmat(dp,n);
return 0;
}
| [
"io.output.change"
] | 976,909 | 976,910 | u297190465 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long // Short form for long long
#define ld long double // Short form for long double
#define fl float
typedef pair<ll, ll> pii; // Pair of long long
typedef vector<ll> vi; // Vector of long long
typedef vector<fl> vf;
typedef vector<ld> vd; // Vector of long double
typedef vector<vi> vvi; // Vector of vector of long long
typedef vector<vd> vvd;
typedef vector<vf> vvf;
typedef vector<pii> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of vector of pairs
#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 // Pushback 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
ll mod = 1e9 + 7;
ll t = 1;
// vvi adj;
ll n, m, x, y;
vi dp, vis;
// vvf adj;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// cin>>t;
while (t--) {
cin >> n;
ld adj[n][n + 1] = {0};
ld a[n];
// adj.resize(n+1);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i <= n; i++)
adj[0][i] = 0;
// for(int i=1;i<=n;i++){
// for(int j=0;j<=n;j++)adj[i].pb(0);
// }
adj[0][0] = (1 - a[0]);
adj[0][1] = a[0];
for (int i = 1; i < n; i++) {
// if(i==1){adj[i][0] = 1-a[i]; adj[i][1] = a[i];continue;}
// else {
adj[i][0] = adj[i - 1][0] * (1 - a[i]);
for (int j = 1; j <= n; j++) {
adj[i][j] = adj[i - 1][j] * (1 - a[i]) + adj[i - 1][j - 1] * (a[i]);
}
// }
}
ld ans = 0;
ll i = n - 1;
while (i > n / 2) {
ans += adj[n - 1][i];
i--;
}
cout << fixed << setprecision(11) << ans << "\n";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long // Short form for long long
#define ld long double // Short form for long double
#define fl float
typedef pair<ll, ll> pii; // Pair of long long
typedef vector<ll> vi; // Vector of long long
typedef vector<fl> vf;
typedef vector<ld> vd; // Vector of long double
typedef vector<vi> vvi; // Vector of vector of long long
typedef vector<vd> vvd;
typedef vector<vf> vvf;
typedef vector<pii> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of vector of pairs
#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 // Pushback 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
ll mod = 1e9 + 7;
ll t = 1;
// vvi adj;
ll n, m, x, y;
vi dp, vis;
// vvf adj;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// cin>>t;
while (t--) {
cin >> n;
ld adj[n][n + 1] = {0};
ld a[n];
// adj.resize(n+1);
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i <= n; i++)
adj[0][i] = 0;
// for(int i=1;i<=n;i++){
// for(int j=0;j<=n;j++)adj[i].pb(0);
// }
adj[0][0] = (1 - a[0]);
adj[0][1] = a[0];
for (int i = 1; i < n; i++) {
// if(i==1){adj[i][0] = 1-a[i]; adj[i][1] = a[i];continue;}
// else {
adj[i][0] = adj[i - 1][0] * (1 - a[i]);
for (int j = 1; j <= n; j++) {
adj[i][j] = adj[i - 1][j] * (1 - a[i]) + adj[i - 1][j - 1] * (a[i]);
}
// }
}
ld ans = 0;
ll i = n;
while (i > n / 2) {
ans += adj[n - 1][i];
i--;
}
cout << fixed << setprecision(9) << ans << "\n";
}
return 0;
} | [
"expression.operation.binary.remove",
"literal.number.change",
"io.output.change"
] | 976,911 | 976,912 | u151623721 | cpp |
p03168 | #include <bits/stdc++.h>
#define prDouble(x) cout << fixed << setprecision(10) << x
using namespace std;
double dp[3001][3001];
double probability(double *arr, int i, int x) {
if (x == 0) {
return 1;
}
if (i == 0) {
return 0;
}
if (dp[i][x] > -0.1) {
return dp[i][x];
}
return dp[i][x] = arr[i] * probability(arr, i - 1, x - 1) +
(1 - arr[i]) * probability(arr, i - 1, x);
}
int main() {
int n;
cin >> n;
double arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
memset(dp, -1, sizeof(dp));
prDouble(probability(arr, n, (n + 1) / 2));
return 0;
} | #include <bits/stdc++.h>
#define prDouble(x) cout << fixed << setprecision(10) << x
using namespace std;
double dp[3001][3001];
double probability(double *arr, int i, int x) {
if (x == 0) {
return 1;
}
if (i == 0) {
return 0;
}
if (dp[i][x] > -0.9) {
return dp[i][x];
}
return dp[i][x] = arr[i] * probability(arr, i - 1, x - 1) +
(1 - arr[i]) * probability(arr, i - 1, x);
}
int main() {
int n;
cin >> n;
double arr[n + 1];
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
memset(dp, -1, sizeof(dp));
prDouble(probability(arr, n, (n + 1) / 2));
return 0;
} | [
"literal.number.change",
"control_flow.branch.if.condition.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 976,913 | 976,914 | u510516229 | cpp |
p03168 | #include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 1LL << 60;
int main() {
ll N;
cin >> N;
ld *p = new ld[N + 1];
ld *q = new ld[N + 1];
FOR(i, 1, N) {
cin >> p[i];
q[i] = 1 - p[i];
}
ld **dp = new ld *[N + 1];
FOR(i, 0, N) {
dp[i] = new ld[N + 1];
FOR(j, 0, N) { dp[i][j] = 0; }
}
dp[0][0] = 1;
FOR(i, 1, N) {
dp[i][0] = dp[i - 1][0] * q[i];
FOR(j, 1, N) { dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * q[i]; }
}
ld ans = 0;
FOR(i, N / 2 + 1, N) { ans += dp[N][i]; }
printf("%.30lf\n", ans);
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 1LL << 60;
int main() {
ll N;
cin >> N;
ld *p = new ld[N + 1];
ld *q = new ld[N + 1];
FOR(i, 1, N) {
cin >> p[i];
q[i] = 1 - p[i];
}
ld **dp = new ld *[N + 1];
FOR(i, 0, N) {
dp[i] = new ld[N + 1];
FOR(j, 0, N) { dp[i][j] = 0; }
}
dp[0][0] = 1;
FOR(i, 1, N) {
dp[i][0] = dp[i - 1][0] * q[i];
FOR(j, 1, N) { dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * q[i]; }
}
ld ans = 0;
FOR(i, N / 2 + 1, N) { ans += dp[N][i]; }
printf("%.30Lf\n", ans);
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change",
"io.output.change"
] | 976,930 | 976,931 | u379804877 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define vec(x) vector<x>
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pair<int, int>>
#define matrix(x) vector<vector<x>>
#define all(v) v.begin(), v.end()
#define mem(a, b) memset(a, b, sizeof a)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed << setprecision(n)
#define ff first
#define ss second
#define print(x) \
for (auto it : x) \
cout << it << " ";
#define dbg(x) cerr << #x << " :: " << x << endl;
#define dbg2(x, y) \
cerr << #x << " :: " << x << "\t" << #y << " :: " << y << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double pi = acos(-1);
int power(int a, int b, int m = MOD) {
int ans = 1;
while (b > 0) {
if (b & 1)
ans = (ans * a) % m;
a = (a * a) % m;
b >>= 1;
}
return ans;
}
int dir[] = {-1, 0, 1, 0, -1};
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int N = 3000;
void solve() {
int i, j, n;
double ans = 0.0;
cin >> n;
double p[n + 1];
for (i = 1; i <= n; i++)
cin >> p[i];
double dp[n + 1][n + 1]; // dp[i][j] probability of j heads with first i coins
mem(dp, 0.0);
dp[0][0] = 1.0;
for (i = 1; i <= n; i++) {
for (j = 0; j <= i; j++) {
if (j == 0)
dp[i][j] = dp[i - 1][j] * (1.0 - p[i]);
else
dp[i][j] = dp[i - 1][j] * (1.0 - p[i]) + dp[i - 1][j - 1] * p[i];
}
}
for (i = (n + 1) / 2; i <= n; i++)
ans += dp[n][i];
cout << ans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
// cin>>t;
while (t--)
solve();
} | #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define vec(x) vector<x>
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pair<int, int>>
#define matrix(x) vector<vector<x>>
#define all(v) v.begin(), v.end()
#define mem(a, b) memset(a, b, sizeof a)
#define setBits(n) __builtin_popcountll(n)
#define prec(n) fixed << setprecision(n)
#define ff first
#define ss second
#define print(x) \
for (auto it : x) \
cout << it << " ";
#define dbg(x) cerr << #x << " :: " << x << endl;
#define dbg2(x, y) \
cerr << #x << " :: " << x << "\t" << #y << " :: " << y << endl;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double pi = acos(-1);
int power(int a, int b, int m = MOD) {
int ans = 1;
while (b > 0) {
if (b & 1)
ans = (ans * a) % m;
a = (a * a) % m;
b >>= 1;
}
return ans;
}
int dir[] = {-1, 0, 1, 0, -1};
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int N = 3000;
void solve() {
int i, j, n;
double ans = 0.0;
cin >> n;
double p[n + 1];
for (i = 1; i <= n; i++)
cin >> p[i];
double dp[n + 1][n + 1]; // dp[i][j] probability of j heads with first i coins
mem(dp, 0.0);
dp[0][0] = 1.0;
for (i = 1; i <= n; i++) {
for (j = 0; j <= i; j++) {
if (j == 0)
dp[i][j] = dp[i - 1][j] * (1.0 - p[i]);
else
dp[i][j] = dp[i - 1][j] * (1.0 - p[i]) + dp[i - 1][j - 1] * p[i];
}
}
for (i = (n + 1) / 2; i <= n; i++)
ans += dp[n][i];
cout << prec(10) << ans << endl;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
// cin>>t;
while (t--)
solve();
} | [
"io.output.change"
] | 976,932 | 976,933 | u088871523 | cpp |
p03168 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define MAX 3000
#define ll long long
int main() {
int n;
cin >> n;
double a[n];
double dp[n + 1][n + 1];
int i, j;
double sum = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
}
dp[0][0] = 1;
for (i = 1; i <= n; i++) {
dp[0][i] = 0;
dp[i][0] = (1 - a[i - 1]) * dp[i - 1][0];
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
dp[i][j] = a[i - 1] * dp[i - 1][j - 1] + (1 - a[i - 1]) * dp[i - 1][j];
}
}
for (i = (n + 1) / 2; i <= n; i++) {
sum += dp[n][i];
}
cout << sum;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define MAX 3000
#define ll long long
int main() {
int n;
cin >> n;
double a[n];
double dp[n + 1][n + 1];
int i, j;
double sum = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
}
dp[0][0] = 1;
for (i = 1; i <= n; i++) {
dp[0][i] = 0;
dp[i][0] = (1 - a[i - 1]) * dp[i - 1][0];
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
dp[i][j] = a[i - 1] * dp[i - 1][j - 1] + (1 - a[i - 1]) * dp[i - 1][j];
}
}
for (i = (n + 1) / 2; i <= n; i++) {
sum += dp[n][i];
}
cout << setprecision(10) << sum;
}
| [
"io.output.change"
] | 976,934 | 976,935 | u759567410 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define pb push_back
#define ll long long
void test_case() {
ll n, i, j;
cin >> n;
long double p[n];
for (ll i = 0; i < n; i++)
cin >> p[i];
long double dp[n + 1][n + 1] = {};
dp[0][0] = 1;
for (i = 1; i <= n; i++) {
for (j = 0; j <= n; j++) {
if (i >= 1) {
if (j >= 1)
dp[i][j] =
p[i - 1] * dp[i - 1][j - 1] + (1 - p[i - 1]) * dp[i - 1][j];
else
dp[i][j] = (1 - p[i - 1]) * dp[i - 1][j];
}
}
}
long double sum = 0;
for (i = n / 2 + 1; i <= n; i++)
sum += dp[n][i];
cout << sum;
}
int main() {
fastio
// int t;
// cin>>t;
// while(t--)
test_case();
}
| #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define pb push_back
#define ll long long
void test_case() {
ll n, i, j;
cin >> n;
long double p[n];
for (ll i = 0; i < n; i++)
cin >> p[i];
long double dp[n + 1][n + 1] = {};
dp[0][0] = 1;
for (i = 1; i <= n; i++) {
for (j = 0; j <= n; j++) {
if (i >= 1) {
if (j >= 1)
dp[i][j] =
p[i - 1] * dp[i - 1][j - 1] + (1 - p[i - 1]) * dp[i - 1][j];
else
dp[i][j] = (1 - p[i - 1]) * dp[i - 1][j];
}
}
}
long double sum = 0;
for (i = n / 2 + 1; i <= n; i++)
sum += dp[n][i];
cout << setprecision(10) << sum;
}
int main() {
fastio
// int t;
// cin>>t;
// while(t--)
test_case();
}
| [
"io.output.change"
] | 976,936 | 976,937 | u886696637 | cpp |
p03168 | // itne me hi thakk gaye?
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O3")
#define ll long long
#define ull unsigned long long
using ld = long double;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll rk = 256;
const ld PI = 3.141592653589793;
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll, ll>
#define pls pair<ll, string>
#define psl pair<string, ll>
#define plc pair<ll, char>
#define pcl pair<char, ll>
#define pss pair<string, string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define print(a) \
for (auto j : a) { \
cout << j << ","; \
} \
cout << "\n";
#define endl '\n'
#define whatis(x) cout << "> " << #x << " ==> " << x << endl;
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
// // Printing pair
ostream &operator<<(ostream &os, pair<ll, ll> const &x) {
os << x.first << "," << x.second;
return os;
}
// printing vector
template <class T> ostream &operator<<(ostream &os, vector<T> const &x) {
os << "{ ";
for (auto &y : x)
os << y << " ";
return os << "}";
}
// printing set
template <class T> ostream &operator<<(ostream &os, set<T> const &x) {
os << "{ ";
for (auto &y : x)
os << y << " ";
return os << "}";
}
template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os,
Container const &x) {
os << "{ ";
for (auto &y : x)
os << y << " ";
return os << "}";
}
template <class X, class Y>
ostream &operator<<(ostream &os, pair<X, Y> const &p) {
return os << "[ " << p.first << ", " << p.second << "]";
}
const int mxn = 1e5 + 5;
int32_t main() {
FastIO;
int n;
cin >> n;
vc<double> arr(n);
for (int i = 0; i < n; i++)
cin >> arr[i];
vc<vc<double>> dp(n + 1, vc<double>(n + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[i][i] = dp[i - 1][i - 1] * arr[i - 1];
dp[i][0] = dp[i - 1][0] * (1 - arr[i - 1]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
dp[i][j] =
(dp[i - 1][j - 1] * arr[i - 1]) + (dp[i - 1][j] * (1 - arr[i - 1]));
}
}
// for(auto i: dp) {
// cout << i << endl;
// }
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << ans << endl;
return 0;
}
| // itne me hi thakk gaye?
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O3")
#define ll long long
#define ull unsigned long long
using ld = long double;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll rk = 256;
const ld PI = 3.141592653589793;
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll, ll>
#define pls pair<ll, string>
#define psl pair<string, ll>
#define plc pair<ll, char>
#define pcl pair<char, ll>
#define pss pair<string, string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define print(a) \
for (auto j : a) { \
cout << j << ","; \
} \
cout << "\n";
#define endl '\n'
#define whatis(x) cout << "> " << #x << " ==> " << x << endl;
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
// // Printing pair
ostream &operator<<(ostream &os, pair<ll, ll> const &x) {
os << x.first << "," << x.second;
return os;
}
// printing vector
template <class T> ostream &operator<<(ostream &os, vector<T> const &x) {
os << "{ ";
for (auto &y : x)
os << y << " ";
return os << "}";
}
// printing set
template <class T> ostream &operator<<(ostream &os, set<T> const &x) {
os << "{ ";
for (auto &y : x)
os << y << " ";
return os << "}";
}
template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os,
Container const &x) {
os << "{ ";
for (auto &y : x)
os << y << " ";
return os << "}";
}
template <class X, class Y>
ostream &operator<<(ostream &os, pair<X, Y> const &p) {
return os << "[ " << p.first << ", " << p.second << "]";
}
const int mxn = 1e5 + 5;
int32_t main() {
FastIO;
int n;
cin >> n;
vc<double> arr(n);
for (int i = 0; i < n; i++)
cin >> arr[i];
vc<vc<double>> dp(n + 1, vc<double>(n + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[i][i] = dp[i - 1][i - 1] * arr[i - 1];
dp[i][0] = dp[i - 1][0] * (1 - arr[i - 1]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
dp[i][j] =
(dp[i - 1][j - 1] * arr[i - 1]) + (dp[i - 1][j] * (1 - arr[i - 1]));
}
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << setprecision(10) << ans << endl;
return 0;
}
| [
"io.output.change"
] | 976,938 | 976,939 | u207533939 | cpp |
p03168 | #pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef priority_queue<int> pq;
typedef priority_queue<int, vi, greater<int>> mpq;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int dX[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define whatis(x) cerr << #x << " is " << x << endl;
#define endl "\n"
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft front()
#define bk back()
#define sz(x) (long long)x.size()
#define all(x) (x).begin(), (x).end()
#define ub upper_bound
#define lb lower_bound
#define FOR(i, a) for (int i = 0; i < a; i++)
#define FoR(i, a) for (int i = 1; i <= a; i++)
#define ROF(i, a) for (int i = (a)-1; i >= 0; i--)
#define error(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
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...);
}
//-----------------------| Template By: DakDak |----------------------------
int n;
double p[3000];
double dp[3000][3000];
int main() {
cin >> n;
FOR(i, n) { cin >> p[i]; }
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 - p[i - 1]);
} else {
dp[i][j] =
(dp[i - 1][j] * (1 - p[i - 1])) + (dp[i - 1][j - 1] * p[i - 1]);
}
}
}
double ans = 0.0;
for (int i = (n + 1) / 2; i <= n; i++) {
ans += dp[n][i];
}
cout << ans << endl;
return 0;
// Read notes to self
}
/* NOTES TO SELF:
* Check for int vs ll, worst case just switch everything to ll
* Check for array bounds if you SEGFAULT, especially in range based loops
* Always initialize everything in global
* Edge cases such as n = 1 or 0
* Make sure to calculate big O complexity
* You are geniosity you got this
*/
| #pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef priority_queue<int> pq;
typedef priority_queue<int, vi, greater<int>> mpq;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int dX[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define whatis(x) cerr << #x << " is " << x << endl;
#define endl "\n"
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ft front()
#define bk back()
#define sz(x) (long long)x.size()
#define all(x) (x).begin(), (x).end()
#define ub upper_bound
#define lb lower_bound
#define FOR(i, a) for (int i = 0; i < a; i++)
#define FoR(i, a) for (int i = 1; i <= a; i++)
#define ROF(i, a) for (int i = (a)-1; i >= 0; i--)
#define error(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
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...);
}
//-----------------------| Template By: DakDak |----------------------------
int n;
double p[3000];
double dp[3000][3000];
int main() {
cin >> n;
FOR(i, n) { cin >> p[i]; }
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 - p[i - 1]);
} else {
dp[i][j] =
(dp[i - 1][j] * (1 - p[i - 1])) + (dp[i - 1][j - 1] * p[i - 1]);
}
}
}
double ans = 0.0;
for (int i = (n + 1) / 2; i <= n; i++) {
ans += dp[n][i];
}
cout << setprecision(100) << ans << endl;
return 0;
// Read notes to self
}
/* NOTES TO SELF:
* Check for int vs ll, worst case just switch everything to ll
* Check for array bounds if you SEGFAULT, especially in range based loops
* Always initialize everything in global
* Edge cases such as n = 1 or 0
* Make sure to calculate big O complexity
* You are geniosity you got this
*/
| [
"io.output.change"
] | 976,942 | 976,943 | u075255886 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define FASTIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
double dp[3002][3002];
double solve(vector<double> &v, int n, int x) {
// 0 heads required always 1
if (x == 0)
return 1;
// for (0,0) it will be 1 only
// Can't get the desired no. of heads in 0 tosses
if (n == 0)
return 0;
if (dp[n][x] > -0.9)
return dp[n][x];
dp[n][x] = v[n] * solve(v, n - 1, x - 1) + (1 - v[n]) * solve(v, n - 1, x);
// cout<<dp[n][x]<<endl;
return dp[n][x];
}
int main() {
FASTIO;
int n;
cin >> n;
vector<double> v(n);
memset(dp, -1, sizeof dp);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
// out of n tosses we want atleast (n+1)/2 heads
double ans = solve(v, n, (n + 1) / 2);
cout << fixed << setprecision(10) << ans;
}
| #include <bits/stdc++.h>
using namespace std;
#define FASTIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
double dp[3002][3002];
double solve(vector<double> &v, int n, int x) {
// 0 heads required always 1
if (x == 0)
return 1;
// for (0,0) it will be 1 only
// Can't get the desired no. of heads in 0 tosses
if (n == 0)
return 0;
if (dp[n][x] > -0.9)
return dp[n][x];
dp[n][x] = v[n] * solve(v, n - 1, x - 1) + (1 - v[n]) * solve(v, n - 1, x);
// cout<<dp[n][x]<<endl;
return dp[n][x];
}
int main() {
FASTIO;
int n;
cin >> n;
vector<double> v(n + 1);
memset(dp, -1, sizeof dp);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
// out of n tosses we want atleast (n+1)/2 heads
double ans = solve(v, n, (n + 1) / 2);
cout << fixed << setprecision(10) << ans;
}
| [
"assignment.change"
] | 976,946 | 976,947 | u294694938 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define FASTIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
double dp[3001][3001];
double solve(vector<double> &v, int n, int x) {
// 0 heads required always 1
if (x == 0)
return 1;
// for (0,0) it will be 1 only
// Can't get the desired no. of heads in 0 tosses
if (n == 0)
return 0;
if (dp[n][x] > -0.9)
return dp[n][x];
dp[n][x] = v[n] * solve(v, n - 1, x - 1) + (1 - v[n]) * solve(v, n - 1, x);
// cout<<dp[n][x]<<endl;
return dp[n][x];
}
int main() {
FASTIO;
int n;
cin >> n;
vector<double> v(n);
memset(dp, -1, sizeof dp);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
// out of n tosses we want atleast (n+1)/2 heads
double ans = solve(v, n, (n + 1) / 2);
cout << fixed << setprecision(10) << ans;
}
| #include <bits/stdc++.h>
using namespace std;
#define FASTIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
double dp[3002][3002];
double solve(vector<double> &v, int n, int x) {
// 0 heads required always 1
if (x == 0)
return 1;
// for (0,0) it will be 1 only
// Can't get the desired no. of heads in 0 tosses
if (n == 0)
return 0;
if (dp[n][x] > -0.9)
return dp[n][x];
dp[n][x] = v[n] * solve(v, n - 1, x - 1) + (1 - v[n]) * solve(v, n - 1, x);
// cout<<dp[n][x]<<endl;
return dp[n][x];
}
int main() {
FASTIO;
int n;
cin >> n;
vector<double> v(n + 1);
memset(dp, -1, sizeof dp);
for (int i = 1; i <= n; i++) {
cin >> v[i];
}
// out of n tosses we want atleast (n+1)/2 heads
double ans = solve(v, n, (n + 1) / 2);
cout << fixed << setprecision(10) << ans;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 976,948 | 976,947 | u294694938 | cpp |
p03168 | /************
* @Just Another Source code by: ankit.sangwan1999
* @created on: 22 May 2020
*/
#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL) //;cout.tie(NULL)
#define ll long long
const int mod = 1e9 + 7;
#define endl '\n'
const int N = 3000;
long double arr[N];
signed main() {
fastio;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
long double dp[n + 1][n + 1];
for (int i = 0; i <= n; i++) { // ith toss
for (int j = 0; j <= n; j++) {
if (i == 0 and j == 0) {
dp[i][j] = 1;
} else if (j == 0) {
dp[i][j] = dp[i - 1][j] * (1 - arr[i - 1]);
} else if (i == 0) {
dp[i][j] = 0;
} else {
dp[i][j] =
dp[i - 1][j] * (1 - arr[i - 1]) + dp[i - 1][j - 1] * arr[i - 1];
}
}
}
long double ans = 0;
for (int i = n - n / 2; i <= n; i++) { // ith toss
ans += dp[n][i];
}
cout << ans;
return 0;
} | /************
* @Just Another Source code by: ankit.sangwan1999
* @created on: 22 May 2020
*/
#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL) //;cout.tie(NULL)
#define ll long long
const int mod = 1e9 + 7;
#define endl '\n'
const int N = 3000;
long double arr[N];
signed main() {
fastio;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
long double dp[n + 1][n + 1];
for (int i = 0; i <= n; i++) { // ith toss
for (int j = 0; j <= n; j++) {
if (i == 0 and j == 0) {
dp[i][j] = 1;
} else if (j == 0) {
dp[i][j] = dp[i - 1][j] * (1 - arr[i - 1]);
} else if (i == 0) {
dp[i][j] = 0;
} else {
dp[i][j] =
dp[i - 1][j] * (1 - arr[i - 1]) + dp[i - 1][j - 1] * arr[i - 1];
}
}
}
long double ans = 0;
for (int i = n - n / 2; i <= n; i++) { // ith toss
ans += dp[n][i];
}
cout << setprecision(10) << ans;
return 0;
} | [
"io.output.change"
] | 976,949 | 976,950 | u808647942 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1001001001;
int main() {
int n;
cin >> n;
vector<double> p(n);
rep(i, n) cin >> p[i];
// dp[i][j] i番目までで j枚表になる確率
vvd dp(n + 1, vector<double>(n + 1, 0.0));
dp[0][0] = 1.0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
// i番目が裏(jはそのまま)
dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
// i番目が表(jも増える)
dp[i + 1][j + 1] += dp[i][j] * p[i];
}
}
// rep(i,n+1)
// {
// rep(j,n+1) cout << dp[i][j] << " ";
// cout << endl;
// }
double ans = 0.0;
//半分以上の確率をタス
for (int i = n / 2 + 1; i <= n; i++)
ans += dp[n][i];
printf("%.2lf\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1001001001;
int main() {
int n;
cin >> n;
vector<double> p(n);
rep(i, n) cin >> p[i];
// dp[i][j] i番目までで j枚表になる確率
vvd dp(n + 1, vector<double>(n + 1, 0.0));
dp[0][0] = 1.0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
// i番目が裏(jはそのまま)
dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
// i番目が表(jも増える)
dp[i + 1][j + 1] += dp[i][j] * p[i];
}
}
// rep(i,n+1)
// {
// rep(j,n+1) cout << dp[i][j] << " ";
// cout << endl;
// }
double ans = 0.0;
//半分以上の確率をタス
for (int i = n / 2 + 1; i <= n; i++)
ans += dp[n][i];
printf("%.10lf\n", ans);
}
| [
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 976,951 | 976,952 | u493928141 | cpp |
p03168 |
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define sp(x) fixed << setprecision(x)
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
// vector<vector<double>> dp(3001,vector<double>(3001,-1));
double dp[3001][3001];
double fun(vector<double> &p, int i, int atleast_heads) {
// Base case
if (atleast_heads == 0)
return 1;
if (i == 0)
return 0;
// Lookup
if (dp[i][atleast_heads] > -0.9)
return dp[i][atleast_heads];
// Rec case
// double op1 = p[i]*fun(p,i-1,atleast_heads-1);
// double op2 = (1-p[i])*fun(p,i-1,atleast_heads);
return dp[i][atleast_heads] = p[i] * fun(p, i - 1, atleast_heads - 1) +
(1 - p[i]) * fun(p, i - 1, atleast_heads);
}
int main() {
fast_io;
memset(dp, -1, sizeof(dp));
int n;
cin >> n;
vector<double> p(n);
for (int i = 1; i <= n; i++)
cin >> p[i];
cout << sp(10) << fun(p, n, (n + 1) / 2) << endl;
return 0;
} |
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define sp(x) fixed << setprecision(x)
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
// vector<vector<double>> dp(3001,vector<double>(3001,-1));
double dp[3001][3001];
double fun(vector<double> &p, int i, int atleast_heads) {
// Base case
if (atleast_heads == 0)
return 1;
if (i == 0)
return 0;
// Lookup
if (dp[i][atleast_heads] > -0.9)
return dp[i][atleast_heads];
// Rec case
// double op1 = p[i]*fun(p,i-1,atleast_heads-1);
// double op2 = (1-p[i])*fun(p,i-1,atleast_heads);
return dp[i][atleast_heads] = p[i] * fun(p, i - 1, atleast_heads - 1) +
(1 - p[i]) * fun(p, i - 1, atleast_heads);
}
int main() {
fast_io;
memset(dp, -1, sizeof(dp));
int n;
cin >> n;
vector<double> p(n + 1);
for (int i = 1; i <= n; i++)
cin >> p[i];
cout << sp(10) << fun(p, n, (n + 1) / 2) << endl;
return 0;
} | [
"assignment.change"
] | 976,955 | 976,956 | u441400811 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double p[n];
for (int i = 0; i < n; i++) {
/* code */
cin >> p[i];
}
// for (int i = 0; i < n; i++)
// {
// /* code */
// cout<<p[i]<<" ";
// }
double dp[n + 1][n + 1];
for (int i = 0; i < n + 1; ++i) {
/* code */
for (int j = 0; j < n + 1; ++j) {
/* code */
dp[i][j] = 0;
}
}
dp[0][0] = 1;
// dp[row][col]--> row=no. of trials and col=heads
for (int row = 1; row < n + 1; row++) {
for (int col = 0; col <= n; col++) {
/* code */
if (col == 0) {
dp[row][col] = (1 - p[row - 1]) * dp[row - 1][col];
} else {
dp[row][col] = (p[row - 1] * dp[row - 1][col - 1]) +
((1 - p[row - 1]) * dp[row - 1][col]);
}
}
}
double sum = 0;
for (int i = n; i > n / 2; i--) {
sum += dp[n][i];
}
cout << sum;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double p[n];
for (int i = 0; i < n; i++) {
/* code */
cin >> p[i];
}
// for (int i = 0; i < n; i++)
// {
// /* code */
// cout<<p[i]<<" ";
// }
double dp[n + 1][n + 1];
for (int i = 0; i < n + 1; ++i) {
/* code */
for (int j = 0; j < n + 1; ++j) {
/* code */
dp[i][j] = 0;
}
}
dp[0][0] = 1;
// dp[row][col]--> row=no. of trials and col=heads
for (int row = 1; row < n + 1; row++) {
for (int col = 0; col <= n; col++) {
/* code */
if (col == 0) {
dp[row][col] = (1 - p[row - 1]) * dp[row - 1][col];
} else {
dp[row][col] = (p[row - 1] * dp[row - 1][col - 1]) +
((1 - p[row - 1]) * dp[row - 1][col]);
}
}
}
double sum = 0;
for (int i = n; i > n / 2; i--) {
sum += dp[n][i];
}
cout << setprecision(10) << sum;
}
| [
"io.output.change"
] | 976,957 | 976,958 | u589362760 | cpp |
p03168 | // Created by Tanuj Jain
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
template <class T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MAXN = 3002;
double dp[MAXN][MAXN], prob[MAXN];
bool vis[MAXN][MAXN], N;
double recursive(int N, int heads) {
// base case
if (N < heads)
return 0.0;
if (N == 0)
return (heads == 0);
if (vis[N][heads])
return dp[N][heads];
else {
// mark the node as visited
vis[N][heads] = true;
// find the left and right child values and save it in dp table
// if i toss the nthe coin i can get a head and a tail
// if i get a head then i need the ansewer for n-1 and heads-1
// if i get a tailt thena i need the answer for n-1 and heads
return dp[N][heads] = (prob[N] * (recursive(N - 1, heads - 1)) +
(1.0 - prob[N]) * (recursive(N - 1, heads)));
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//#ifndef ONLINE_JUDGE
// freopen("inputf.in","r",stdin);
// freopen("outputf.in","w",stdout);
//#endif
int N;
cin >> N;
for (int i = 1; i <= N; i++)
cin >> prob[i];
double ans = 0;
for (int heads = 0; heads < N; heads++) {
int tails = N - heads;
if (heads > tails) {
ans += recursive(N, heads);
}
}
cout << fixed << setprecision(9) << ans;
} | // Created by Tanuj Jain
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
template <class T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MAXN = 3002;
double dp[MAXN][MAXN], prob[MAXN];
bool vis[MAXN][MAXN], N;
double recursive(int N, int heads) {
// base case
if (N < heads)
return 0.0;
if (N == 0)
return (heads == 0);
if (vis[N][heads])
return dp[N][heads];
else {
// mark the node as visited
vis[N][heads] = true;
// find the left and right child values and save it in dp table
// if i toss the nthe coin i can get a head and a tail
// if i get a head then i need the ansewer for n-1 and heads-1
// if i get a tailt thena i need the answer for n-1 and heads
return dp[N][heads] = (prob[N] * (recursive(N - 1, heads - 1)) +
(1.0 - prob[N]) * (recursive(N - 1, heads)));
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//#ifndef ONLINE_JUDGE
// freopen("inputf.in","r",stdin);
// freopen("outputf.in","w",stdout);
//#endif
int N;
cin >> N;
for (int i = 1; i <= N; i++)
cin >> prob[i];
double ans = 0;
for (int heads = 0; heads <= N; heads++) {
int tails = N - heads;
if (heads > tails) {
ans += recursive(N, heads);
}
}
cout << fixed << setprecision(9) << ans;
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 976,966 | 976,967 | u604854220 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int n;
cin >> n;
double p[n + 1];
for (ll i = 1; i <= n; i++)
cin >> p[i];
double dp[n + 1][n + 1];
for (ll i = 0; i <= n; i++)
for (ll j = 0; j <= n; j++)
dp[i][j] = 0;
dp[0][0] = 1;
for (ll i = 1; i <= n; i++) {
dp[i][0] = (1 - p[i]) * dp[i - 1][0];
for (ll j = 1; j <= i; j++) {
// if(j==i)
// {
// dp[i][j]=p[i]*dp[i-1][j-1];
// continue;
// }
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][i];
cout << fixed;
cout << setprecision(3) << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int n;
cin >> n;
double p[n + 1];
for (ll i = 1; i <= n; i++)
cin >> p[i];
double dp[n + 1][n + 1];
for (ll i = 0; i <= n; i++)
for (ll j = 0; j <= n; j++)
dp[i][j] = 0;
dp[0][0] = 1;
for (ll i = 1; i <= n; i++) {
dp[i][0] = (1 - p[i]) * dp[i - 1][0];
for (ll j = 1; j <= i; j++) {
// if(j==i)
// {
// dp[i][j]=p[i]*dp[i-1][j-1];
// continue;
// }
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][i];
cout << fixed;
cout << setprecision(10) << ans;
} | [
"literal.number.change",
"io.output.change"
] | 976,974 | 976,975 | u429860633 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int n;
cin >> n;
double p[n + 1];
for (ll i = 1; i <= n; i++)
cin >> p[i];
double dp[n + 1][n + 1];
for (ll i = 0; i <= n; i++)
for (ll j = 0; j <= n; j++)
dp[i][j] = 0;
dp[0][0] = 1;
for (ll i = 1; i <= n; i++) {
dp[i][0] = (1 - p[i]) * dp[i - 1][0];
for (ll j = 1; j <= i; j++) {
// if(j==i)
// {
// dp[i][j]=p[i]*dp[i-1][j-1];
// continue;
// }
dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
}
}
double ans = 0;
for (ll i = (n / 2) + 1; i <= n; i++)
ans += dp[n][i];
cout << fixed;
cout << setprecision(3) << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
int n;
cin >> n;
double p[n + 1];
for (ll i = 1; i <= n; i++)
cin >> p[i];
double dp[n + 1][n + 1];
for (ll i = 0; i <= n; i++)
for (ll j = 0; j <= n; j++)
dp[i][j] = 0;
dp[0][0] = 1;
for (ll i = 1; i <= n; i++) {
dp[i][0] = (1 - p[i]) * dp[i - 1][0];
for (ll j = 1; j <= i; j++) {
// if(j==i)
// {
// dp[i][j]=p[i]*dp[i-1][j-1];
// continue;
// }
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][i];
cout << fixed;
cout << setprecision(10) << ans;
} | [
"control_flow.loop.for.initializer.change",
"variable_declaration.type.change",
"literal.number.change",
"io.output.change"
] | 976,976 | 976,975 | u429860633 | cpp |
p03168 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int, int>
#define fr(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
#define nl '\n'
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
double dp[3000][3000];
double arr[3000];
double solve(int i, int cnt, int n) {
if (i > n) {
if (cnt > n / 2)
return 1;
else
return 0;
}
if (dp[i][cnt] != -1.0)
return dp[i][cnt];
double ans =
(1 - arr[i]) * solve(i + 1, cnt, n) + arr[i] * solve(i + 1, cnt + 1, n);
return dp[i][cnt] = ans;
}
int32_t main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> arr[i];
for (int i = 0; i < 3000; i++) {
for (int j = 0; j < 3000; j++)
dp[i][j] = -1.0;
}
cout << solve(1, 0, n) << endl;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int, int>
#define fr(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
#define nl '\n'
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
double dp[3000][3000];
double arr[3000];
double solve(int i, int cnt, int n) {
if (i > n) {
if (cnt > n / 2)
return 1;
else
return 0;
}
if (dp[i][cnt] != -1.0)
return dp[i][cnt];
double ans =
(1 - arr[i]) * solve(i + 1, cnt, n) + arr[i] * solve(i + 1, cnt + 1, n);
return dp[i][cnt] = ans;
}
int32_t main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> arr[i];
for (int i = 0; i < 3000; i++) {
for (int j = 0; j < 3000; j++)
dp[i][j] = -1.0;
}
cout << setprecision(10) << solve(1, 0, n) << endl;
} | [
"io.output.change"
] | 976,977 | 976,978 | u146209432 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
void cc_env() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
//
#endif
}
int main() {
// cc_env();
// input part
int N;
cin >> N;
vector<double> inputArr(N);
for (int i = 0; i < N; i++)
cin >> inputArr[i];
// processing part
vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0.0));
// base case
dp[0][0] = 1.0;
for (int j = 1; j <= N; j++)
dp[j][0] = dp[j - 1][0] * (1.0 - inputArr[j - 1]);
for (int i = 0; i < N + 1; i++) { // turn
for (int j = 1; j < N + 1; j++) { // number of head
if (j <= i) {
dp[i][j] = (dp[i - 1][j - 1] * inputArr[i - 1]) +
dp[i - 1][j] * (1.0 - inputArr[i - 1]);
}
}
}
double ans = 0;
for (int i = N / 2 + 1; i <= N; i++)
ans += dp[N][i];
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
void cc_env() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
//
#endif
}
int main() {
// cc_env();
// input part
int N;
cin >> N;
vector<double> inputArr(N);
for (int i = 0; i < N; i++)
cin >> inputArr[i];
// processing part
vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0.0));
// base case
dp[0][0] = 1.0;
for (int j = 1; j <= N; j++)
dp[j][0] = dp[j - 1][0] * (1.0 - inputArr[j - 1]);
for (int i = 0; i < N + 1; i++) { // turn
for (int j = 1; j < N + 1; j++) { // number of head
if (j <= i) {
dp[i][j] = (dp[i - 1][j - 1] * inputArr[i - 1]) +
dp[i - 1][j] * (1.0 - inputArr[i - 1]);
}
}
}
double ans = 0;
for (int i = N / 2 + 1; i <= N; i++)
ans += dp[N][i];
cout << setprecision(10) << ans << endl;
}
| [
"io.output.change"
] | 976,989 | 976,990 | u733591334 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
void start() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
double p[3001];
double dp[3001][3001];
double solve(int coins, int head) {
if (head <= 0) {
return 1;
}
if (coins == 0)
return 0;
if (dp[coins][head] > -1)
return dp[coins][head];
double op1 = p[coins] * solve(coins - 1, head - 1);
double op2 = (1 - p[coins]) * solve(coins - 1, head);
dp[coins][head] = op1 + op2;
return op1 + op2;
}
int32_t main() {
fastIO start();
memset(dp, -1, sizeof(dp));
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i];
cout << fixed << setprecision(11) << solve(n, (n + 1) / 2);
// it is said that we need more heads than tails so i
// opted for n+1/2 heads
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
void start() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
double p[3001];
double dp[3001][3001];
double solve(int coins, int head) {
if (head <= 0) {
return 1;
}
if (coins == 0)
return 0;
if (dp[coins][head] > -1)
return dp[coins][head];
double op1 = p[coins] * solve(coins - 1, head - 1);
double op2 = (1 - p[coins]) * solve(coins - 1, head);
dp[coins][head] = op1 + op2;
return op1 + op2;
}
int32_t main() {
fastIO
// start();
memset(dp, -1, sizeof(dp));
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i];
cout << fixed << setprecision(11) << solve(n, (n + 1) / 2);
// it is said that we need more heads than tails so i
// opted for n+1/2 heads
} | [
"variable_declaration.remove"
] | 977,002 | 977,003 | u948429045 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()
const long long INF = 1LL << 60;
const int mod = 1000000007;
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;
}
int N;
vector<double> p;
vector<vector<double>> dp(3010, vector<double>(10000));
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> N;
p.resize(N);
REP(i, N) cin >> p.at(i);
dp[0][0] = 1.0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dp[i + 1][j + 1] += dp[i][j] * p[i];
dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
}
}
double ans = 0;
for (int i = 0; i < (N + 1) / 2; i++) {
ans += dp[N][i];
}
cout << setprecision(6) << (double)1.0 - ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()
const long long INF = 1LL << 60;
const int mod = 1000000007;
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;
}
int N;
vector<double> p;
vector<vector<double>> dp(3010, vector<double>(10000));
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> N;
p.resize(N);
REP(i, N) cin >> p.at(i);
dp[0][0] = 1.0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dp[i + 1][j + 1] += dp[i][j] * p[i];
dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
}
}
double ans = 0;
for (int i = 0; i < (N + 1) / 2; i++) {
ans += dp[N][i];
}
cout << setprecision(10) << (double)1.0 - ans << endl;
return 0;
} | [
"literal.number.change",
"io.output.change"
] | 977,004 | 977,005 | u848058000 | cpp |
p03168 | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define gc(x) \
do { \
while ((x = getchar()) < '0') \
; \
for (x -= '0'; '0' <= (_ = getchar()); x = (x << 3) + (x << 1) + _ - '0') \
; \
} while (0)
#define ms(a, b) memset(a, b, sizeof(a));
char _;
typedef long double dl;
using namespace std;
dl arr[3000];
dl dp[3000][3000];
dl headsprob(int tosses, int heads) {
if (tosses < 0 || heads < 0) {
return 0;
} else if (dp[tosses][heads] != -1) {
return dp[tosses][heads];
} else {
if (heads > tosses) {
dp[tosses][heads] = 0;
} else {
dp[tosses][heads] = headsprob(tosses - 1, heads - 1) * (arr[tosses]);
dp[tosses][heads] += headsprob(tosses - 1, heads) * ((dl)1 - arr[tosses]);
}
return dp[tosses][heads];
}
}
int main() {
ms(dp, -1);
dp[0][0] = 1;
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
dl a;
cin >> a;
arr[i + 1] = a;
}
dl const1 = 0;
for (int i = n / 2 + 1; i <= n; ++i) {
const1 += headsprob(n, i);
}
cout << const1 << "\n";
return 0;
}
| #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define gc(x) \
do { \
while ((x = getchar()) < '0') \
; \
for (x -= '0'; '0' <= (_ = getchar()); x = (x << 3) + (x << 1) + _ - '0') \
; \
} while (0)
#define ms(a, b) memset(a, b, sizeof(a));
char _;
typedef long double dl;
using namespace std;
dl arr[3000];
dl dp[3000][3000];
dl headsprob(int tosses, int heads) {
if (tosses < 0 || heads < 0) {
return 0;
} else if (dp[tosses][heads] != -1) {
return dp[tosses][heads];
} else {
if (heads > tosses) {
dp[tosses][heads] = 0;
} else {
dp[tosses][heads] = headsprob(tosses - 1, heads - 1) * (arr[tosses]);
dp[tosses][heads] += headsprob(tosses - 1, heads) * ((dl)1 - arr[tosses]);
}
return dp[tosses][heads];
}
}
int main() {
ms(dp, -1);
dp[0][0] = 1;
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
dl a;
cin >> a;
arr[i + 1] = a;
}
dl const1 = 0;
for (int i = n / 2 + 1; i <= n; ++i) {
const1 += headsprob(n, i);
}
cout << setprecision(16) << const1 << "\n";
return 0;
}
| [
"io.output.change"
] | 977,006 | 977,007 | u514882008 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
#define _ % MOD
#define __ %= MOD
#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define fill(a) memset(a, 0, sizeof(a))
#define swap(a, b) \
{ \
a = a + b; \
b = a - b; \
a = a - b; \
}
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll power(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = res * x;
y = y >> 1;
x = x * x;
}
return res;
} // modular exponent
int main() {
ios_base::sync_with_stdio(false); // don't use printf and scanf
cin.tie(NULL); // cout<<fixed<<setprecision
int n, i, j;
cin >> n;
ld p[n];
ld ans = 0.0;
for (i = 0; i < n; i++)
cin >> p[i];
vector<vector<long double>> M(n + 1, vector<long double>(n + 1, -1.0));
// cout<<"initially M = \n";
/*for(i=0;i<=n;i++)
{
cout<<"\n";
for(j=0;j<=n;j++)
cout<<M[i][j]<<" ";
}*/
for (i = 0; i <= n; i++)
for (j = 0; j < n; j++)
M[i][j] = -1;
M[0][0] = 0;
M[1][0] = 100 * (1 - p[0]);
M[1][1] = 100 * p[0];
for (i = 2; i <= n; i++) {
for (j = 0; j <= n; j++) {
if (j == 0)
M[i][j] = (1 - p[i - 1]) * M[i - 1][j];
else if (j < i) {
M[i][j] = M[i - 1][j] * (1 - p[i - 1]) + M[i - 1][j - 1] * (p[i - 1]);
} else if (j == i)
M[i][j] = M[i - 1][j - 1] * p[i - 1];
}
}
for (i = n / 2 + 1; i <= n; i++) {
ans += M[n][i];
}
ans = ans / 100;
/*cout<<"\n\n";
for(i=0;i<=n;i++)
{
cout<<"\n";
for(j=0;j<=n;j++)
cout<<M[i][j]<<" ";
}*/
cout << ans << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef set<int>::iterator sit;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
#define _ % MOD
#define __ %= MOD
#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.begin(), v.end(), greater<auto>())
#define fill(a) memset(a, 0, sizeof(a))
#define swap(a, b) \
{ \
a = a + b; \
b = a - b; \
a = a - b; \
}
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repA(i, a, n) for (ll i = a; i <= (n); ++i)
#define repD(i, a, n) for (ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll power(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = res * x;
y = y >> 1;
x = x * x;
}
return res;
} // modular exponent
int main() {
ios_base::sync_with_stdio(false); // don't use printf and scanf
cin.tie(NULL); // cout<<fixed<<setprecision
int n, i, j;
cin >> n;
ld p[n];
ld ans = 0.0;
for (i = 0; i < n; i++)
cin >> p[i];
vector<vector<long double>> M(n + 1, vector<long double>(n + 1, -1.0));
// cout<<"initially M = \n";
/*for(i=0;i<=n;i++)
{
cout<<"\n";
for(j=0;j<=n;j++)
cout<<M[i][j]<<" ";
}*/
for (i = 0; i <= n; i++)
for (j = 0; j < n; j++)
M[i][j] = -1;
M[0][0] = 0;
M[1][0] = 100 * (1 - p[0]);
M[1][1] = 100 * p[0];
for (i = 2; i <= n; i++) {
for (j = 0; j <= n; j++) {
if (j == 0)
M[i][j] = (1 - p[i - 1]) * M[i - 1][j];
else if (j < i) {
M[i][j] = M[i - 1][j] * (1 - p[i - 1]) + M[i - 1][j - 1] * (p[i - 1]);
} else if (j == i)
M[i][j] = M[i - 1][j - 1] * p[i - 1];
}
}
for (i = n / 2 + 1; i <= n; i++) {
ans += M[n][i];
}
ans = ans / 100;
/*cout<<"\n\n";
for(i=0;i<=n;i++)
{
cout<<"\n";
for(j=0;j<=n;j++)
cout<<M[i][j]<<" ";
}*/
cout << setprecision(12) << ans << "\n";
}
| [
"io.output.change"
] | 977,008 | 977,009 | u670454361 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
ll n;
cin >> n;
double arr[n + 1];
for (ll i = 1; i <= n; i++)
cin >> arr[i];
double dp[n + 1][n + 1];
memset(dp, 0.0, sizeof(dp));
dp[0][0] = 1.0;
for (ll i = 1; i <= n; i++) {
for (ll j = 0; j <= n; j++) {
if (j == 0)
dp[i][j] = (1.0 - arr[i]) * dp[i - 1][j];
else {
dp[i][j] = arr[i] * dp[i - 1][j - 1] + (1.0 - arr[i]) * dp[i - 1][j];
}
}
}
double ans = 0.0;
for (ll i = (n / 2) + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
ll n;
cin >> n;
double arr[n + 1];
for (ll i = 1; i <= n; i++)
cin >> arr[i];
double dp[n + 1][n + 1];
memset(dp, 0.0, sizeof(dp));
dp[0][0] = 1.0;
for (ll i = 1; i <= n; i++) {
for (ll j = 0; j <= n; j++) {
if (j == 0)
dp[i][j] = (1.0 - arr[i]) * dp[i - 1][j];
else {
dp[i][j] = arr[i] * dp[i - 1][j - 1] + (1.0 - arr[i]) * dp[i - 1][j];
}
}
}
double ans = 0.0;
for (ll i = (n / 2) + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << setprecision(9) << ans << endl;
}
| [
"io.output.change"
] | 977,012 | 977,013 | u876721855 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int mxN = 4000;
int n;
double p[mxN];
double dp[mxN][mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
if (fopen("input.in", "r")) {
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
}
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i];
dp[0][0] = 1.0;
for (int h = 0; h <= n; h++) {
for (int t = 0; t <= n; t++) {
if (h + t >= n)
continue;
if (h + 1 <= n && h + t + 1 <= n)
dp[h + 1][t] = dp[h + 1][t] + (dp[h][t] * p[h + t + 1]);
if (t + 1 <= n && h + t + 1 <= n)
dp[h][t + 1] = dp[h][t + 1] + (dp[h][t] * (1.0 - p[h + t + 1]));
}
}
double ans = 0.0;
for (int h = 0; h <= n; h++) {
int t = n - h;
if (h > t)
ans += dp[h][t];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int mxN = 4000;
int n;
double p[mxN];
double dp[mxN][mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
if (fopen("input.in", "r")) {
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
}
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i];
dp[0][0] = 1.0;
for (int h = 0; h <= n; h++) {
for (int t = 0; t <= n; t++) {
if (h + t >= n)
continue;
if (h + 1 <= n && h + t + 1 <= n)
dp[h + 1][t] = dp[h + 1][t] + (dp[h][t] * p[h + t + 1]);
if (t + 1 <= n && h + t + 1 <= n)
dp[h][t + 1] = dp[h][t + 1] + (dp[h][t] * (1.0 - p[h + t + 1]));
}
}
double ans = 0.0;
for (int h = 0; h <= n; h++) {
int t = n - h;
if (h > t)
ans += dp[h][t];
}
cout << setprecision(15) << ans << endl;
return 0;
} | [
"io.output.change"
] | 977,018 | 977,019 | u142188850 | cpp |
p03168 | // https://atcoder.jp/contests/dp/tasks/dp_i
#include <bits/stdc++.h>
using namespace std;
typedef long double dl;
int main() {
int n, i, j;
cin >> n;
dl arr[n + 1], dp[n + 1][n + 1],
ans = 0.0; // dp[i][j] means in pos j there are i heads
for (i = 1; i <= n; i++)
cin >> arr[i];
/* for(i=0;i<n;i++)
cout<<arr[i]<<' ';*/
dp[0][0] = 1.0;
for (i = 1; i <= n; i++)
dp[0][i] = (1.0 - arr[i]) * dp[0][i - 1];
for (i = 1; i <= n; i++) {
for (j = i; j <= n; j++) {
if (i == j) {
dp[i][j] = dp[i - 1][i - 1] * arr[i];
} else {
dp[i][j] =
(dp[i][j - 1] * (1.0 - arr[j])) + (dp[i - 1][j - 1] * arr[j]);
}
}
}
/* for(i=0;i<=n;i++)
{
for(j=0;j<=n;j++)
cout<<dp[i][j]<<" ";
cout<<endl;
}*/
for (i = n / 2 + 1; i <= n; i++) {
ans = ans + dp[i][n];
}
printf("%.10lf\n", ans);
}
| // https://atcoder.jp/contests/dp/tasks/dp_i
#include <bits/stdc++.h>
using namespace std;
typedef long double dl;
int main() {
int n, i, j;
cin >> n;
dl arr[n + 1], dp[n + 1][n + 1],
ans = 0.0; // dp[i][j] means in pos j there are i heads
for (i = 1; i <= n; i++)
cin >> arr[i];
/* for(i=0;i<n;i++)
cout<<arr[i]<<' ';*/
dp[0][0] = 1.0;
for (i = 1; i <= n; i++)
dp[0][i] = (1.0 - arr[i]) * dp[0][i - 1];
for (i = 1; i <= n; i++) {
for (j = i; j <= n; j++) {
if (i == j) {
dp[i][j] = dp[i - 1][i - 1] * arr[i];
} else {
dp[i][j] =
(dp[i][j - 1] * (1.0 - arr[j])) + (dp[i - 1][j - 1] * arr[j]);
}
}
}
/* for(i=0;i<=n;i++)
{
for(j=0;j<=n;j++)
cout<<dp[i][j]<<" ";
cout<<endl;
}*/
for (i = n / 2 + 1; i <= n; i++) {
ans = ans + dp[i][n];
}
printf("%.10llf\n", ans);
}
| [
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 977,022 | 977,023 | u736529159 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<double> a(n + 1);
vector<vector<double>> dp(n + 1, vector<double>(n + 1));
for (int i = 1; i <= n; i++)
cin >> a[i];
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i];
}
}
int mid = (n + 1) / 2;
if (n % 2 == 0)
mid++;
double res = 0;
for (int i = mid; i <= n; i++)
res += dp[n][i];
cout << res;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<double> a(n + 1);
vector<vector<double>> dp(n + 1, vector<double>(n + 1));
for (int i = 1; i <= n; i++)
cin >> a[i];
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i];
}
}
int mid = (n + 1) / 2;
if (n % 2 == 0)
mid++;
double res = 0;
for (int i = mid; i <= n; i++)
res += dp[n][i];
cout << setprecision(10) << res;
}
| [
"io.output.change"
] | 977,036 | 977,037 | u895283116 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, a, b) for (int i = (a); i > (b); --i)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int mod = 1e9 + 7;
const ll inf = 2e18 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
double p_heads, p_tails;
double dp[n + 1]; // dp[i] is probability of getting i heads so far. Only 1-D
// array is needed. dp[heads][tails] is not needed because
// tails=n-heads
dp[0] = 1;
loop(i, 0, n) {
cin >> p_heads;
p_tails = 1 - p_heads;
for (int j = i + 1; j >= 0; j--) {
if (j == 0)
dp[j] = dp[j] * p_tails;
else
dp[j] = dp[j - 1] * p_heads +
dp[j] * p_tails; /*this time heads + *this time tails*/
}
}
double ans = 0;
int heads, tails;
for (heads = 0; heads <= n; heads++) {
tails = n - heads;
if (heads > tails)
ans += dp[heads];
}
printf("%.10lf", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, a, b) for (int i = (a); i > (b); --i)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int mod = 1e9 + 7;
const ll inf = 2e18 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
double p_heads, p_tails;
vector<double> dp(
n + 1); // dp[i] is probability of getting i heads so far. Only 1-D array
// is needed. dp[heads][tails] is not needed because tails=n-heads
dp[0] = 1;
loop(i, 0, n) {
cin >> p_heads;
p_tails = 1 - p_heads;
for (int j = i + 1; j >= 0; j--) {
if (j == 0)
dp[j] = dp[j] * p_tails;
else
dp[j] = dp[j - 1] * p_heads +
dp[j] * p_tails; /*this time heads + *this time tails*/
}
}
double ans = 0;
int heads, tails;
for (heads = 0; heads <= n; heads++) {
tails = n - heads;
if (heads > tails)
ans += dp[heads];
}
printf("%.10lf", ans);
return 0;
} | [] | 977,044 | 977,045 | u332824951 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll n;
cin >> n;
double a[n];
ll i, j;
for (i = 0; i < n; i++)
cin >> a[i];
double sol[n][n + 1];
sol[0][0] = 1 - a[0];
sol[0][1] = a[0];
for (i = 2; i <= n; i++)
sol[0][i] = 0;
double sum = 0;
for (i = 1; i < n; i++) {
for (j = 0; j <= n; j++) {
if (j == 0)
sol[i][j] = sol[i - 1][j] * (1 - a[i]);
else
sol[i][j] = sol[i - 1][j] * (1 - a[i]) + sol[i - 1][j - 1] * a[i];
}
}
for (j = n / 2 + 1; j <= n; j++) {
sum = sum + sol[n - 1][j];
}
cout << sum << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll n;
cin >> n;
double a[n];
ll i, j;
for (i = 0; i < n; i++)
cin >> a[i];
double sol[n][n + 1];
sol[0][0] = 1 - a[0];
sol[0][1] = a[0];
for (i = 2; i <= n; i++)
sol[0][i] = 0;
double sum = 0;
for (i = 1; i < n; i++) {
for (j = 0; j <= n; j++) {
if (j == 0)
sol[i][j] = sol[i - 1][j] * (1 - a[i]);
else
sol[i][j] = sol[i - 1][j] * (1 - a[i]) + sol[i - 1][j - 1] * a[i];
}
}
for (j = n / 2 + 1; j <= n; j++) {
sum = sum + sol[n - 1][j];
}
cout << setprecision(10) << sum << endl;
}
| [
"io.output.change"
] | 977,056 | 977,057 | u975400222 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define mp make_pair
#define endl "\n"
#define pii pair<int, int>
#define ff first
#define ss second
#define mii map<int, int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
const int M = 1e9 + 7;
int32_t main() {
IOS;
int n;
cin >> n;
double a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
double dp[n + 1] = {0};
dp[0] = 1;
for (int i = 0; i < n; i++) {
double temp[n + 1] = {0};
for (int j = 0; j < n + 1; j++)
temp[j] = (double)dp[j] * (double)(1 - a[i]);
for (int j = 0; j < n; j++)
temp[j + 1] += (double)dp[j] * (double)(a[i]);
for (int j = 0; j < n + 1; j++)
dp[j] = temp[j];
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[i];
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define mp make_pair
#define endl "\n"
#define pii pair<int, int>
#define ff first
#define ss second
#define mii map<int, int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
const int M = 1e9 + 7;
int32_t main() {
IOS;
int n;
cin >> n;
double a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
double dp[n + 1] = {0};
dp[0] = 1;
for (int i = 0; i < n; i++) {
double temp[n + 1] = {0};
for (int j = 0; j < n + 1; j++)
temp[j] = (double)dp[j] * (double)(1 - a[i]);
for (int j = 0; j < n; j++)
temp[j + 1] += (double)dp[j] * (double)(a[i]);
for (int j = 0; j < n + 1; j++)
dp[j] = temp[j];
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[i];
}
cout << setprecision(12) << ans << endl;
} | [
"io.output.change"
] | 977,058 | 977,059 | u231918578 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
double p;
double dp[n + 1][n + 1];
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
cin >> p;
for (int j = 0; j <= i; j++) {
if (j)
dp[i][j] += p * dp[i - 1][j - 1];
dp[i][j] += (1 - p) * dp[i - 1][j];
}
}
double ans = 0;
for (int i = 0; i <= n; i++)
if (i > n - i)
ans += dp[n][i];
printf("%.12lf\n", ans);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
double p;
double dp[n + 5][n + 5];
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
cin >> p;
for (int j = 0; j <= i; j++) {
if (j)
dp[i][j] += p * dp[i - 1][j - 1];
dp[i][j] += (1 - p) * dp[i - 1][j];
}
}
double ans = 0;
for (int i = 0; i <= n; i++)
if (i > n - i)
ans += dp[n][i];
printf("%.12lf\n", ans);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
} | [
"literal.number.change",
"expression.operation.binary.change"
] | 977,062 | 977,063 | u049015919 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
double p;
double dp[n + 1][n + 1];
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
cin >> p;
for (int j = 0; j <= i; j++) {
if (j)
dp[i][j] += p * dp[i - 1][j - 1];
dp[i][j] += (1 - p) * dp[i - 1][j];
}
}
double ans = 0;
for (int i = 1; i <= n; i++)
if (i > n - i)
ans += dp[n][i];
printf("%.12lf\n", ans);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
double p;
double dp[n + 5][n + 5];
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
cin >> p;
for (int j = 0; j <= i; j++) {
if (j)
dp[i][j] += p * dp[i - 1][j - 1];
dp[i][j] += (1 - p) * dp[i - 1][j];
}
}
double ans = 0;
for (int i = 0; i <= n; i++)
if (i > n - i)
ans += dp[n][i];
printf("%.12lf\n", ans);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
} | [
"literal.number.change",
"expression.operation.binary.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 977,064 | 977,063 | u049015919 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define COUT(x) cout << (x) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using M = map<int, int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int dp[3000][3000]; // [i][j] i枚目のコインを投げたときに表がj枚になる確率
int main() {
int n;
cin >> n;
double p[n];
REP(i, n) cin >> p[i];
dp[0][0] = 1.0;
REP(i, n) {
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.0 - p[i]);
}
}
double res = 0.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;
#define REP(i, n) for (int i = 0; i < n; i++)
#define COUT(x) cout << (x) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using M = map<int, int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
double dp[3000][3000]; // [i][j] i枚目のコインを投げたときに表がj枚になる確率
int main() {
int n;
cin >> n;
double p[n];
REP(i, n) cin >> p[i];
dp[0][0] = 1.0;
REP(i, n) {
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.0 - p[i]);
}
}
double res = 0.0;
for (int i = (n + 1) / 2; i <= n; i++)
res += dp[n][i];
cout << fixed << setprecision(10) << res << endl;
return 0;
} | [
"variable_declaration.type.primitive.change"
] | 977,065 | 977,066 | u303884911 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define REP(i, s, l) for (lli i = s; i < l; i++)
#define DEBUG 0
#define INF (1LL << 50)
#define MOD 1000000007
signed main() {
lli n;
cin >> n;
vector<double> p(n);
REP(i, 0, n) cin >> p[i];
double dp[3010] = {0};
dp[0] = 1.0;
for (lli i = 1; i <= n; i++) {
for (lli j = i; j >= 0; j--) {
dp[j] = dp[j] * (1.0 - p[i - 1]);
if (j > 0)
dp[j] += dp[j - 1] * p[i - 1];
}
}
lli target = n / 2 + 1;
double ans = 0;
REP(i, target, n + 1) ans += dp[i];
printf("%.10llf\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define REP(i, s, l) for (lli i = s; i < l; i++)
#define DEBUG 0
#define INF (1LL << 50)
#define MOD 1000000007
signed main() {
lli n;
cin >> n;
vector<double> p(n);
REP(i, 0, n) cin >> p[i];
double dp[3010] = {0};
dp[0] = 1.0;
for (lli i = 1; i <= n; i++) {
for (lli j = i; j >= 0; j--) {
dp[j] = dp[j] * (1.0 - p[i - 1]);
if (j > 0)
dp[j] += dp[j - 1] * p[i - 1];
}
}
lli target = n / 2 + 1;
double ans = 0;
REP(i, target, n + 1) ans += dp[i];
printf("%.10lf\n", ans);
return 0;
} | [
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 977,071 | 977,072 | u041513069 | cpp |
p03168 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
#define maxl __LONG_LONG_MAX__
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define rev1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) \
cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl;
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl;
#define n_ones(x) __builtin_popcountll(x)
#define n_trailzero(x) __builtin_ctzll(x)
#define n_leadingzero(x) __builtin_clz(x)
#define sz(a) (ll)(a.size())
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef stack<ll> stk;
typedef queue<ll> que;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_setll;
typedef tree<char, null_type, less<char>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_setc;
ll max(int a, ll b) { return max((ll)a, b); }
ll min(int a, ll b) { return min((ll)a, b); }
ll min(ll a, int b) { return min(a, (ll)b); }
ll max(ll a, int b) { return max(a, (ll)b); }
ll mod = 1e9 + 7;
void solve() {
ll n;
cin >> n;
ld p[n + 1];
rep1(i, n + 1) cin >> p[i];
ld dp[n + 1][n + 1];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
rep1(i, n + 1) {
dp[0][i] = (1 - p[i]) * dp[0][i - 1];
for (ll j = 1; j <= i; j++) {
dp[j][i] = p[i] * dp[j - 1][i - 1] + (1 - p[i]) * dp[j][i - 1];
}
}
ld ans = 0;
for (ll i = n / 2 + 1; i <= n; i++)
ans += dp[i][n];
cout << ans << endl;
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t = 1;
// cin>>t;
rep(i, t) solve();
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
#define maxl __LONG_LONG_MAX__
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define rev(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i < n; i++)
#define rev1(i, n) for (int i = n; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) \
cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl;
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl;
#define n_ones(x) __builtin_popcountll(x)
#define n_trailzero(x) __builtin_ctzll(x)
#define n_leadingzero(x) __builtin_clz(x)
#define sz(a) (ll)(a.size())
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef stack<ll> stk;
typedef queue<ll> que;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_setll;
typedef tree<char, null_type, less<char>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_setc;
ll max(int a, ll b) { return max((ll)a, b); }
ll min(int a, ll b) { return min((ll)a, b); }
ll min(ll a, int b) { return min(a, (ll)b); }
ll max(ll a, int b) { return max(a, (ll)b); }
ll mod = 1e9 + 7;
void solve() {
ll n;
cin >> n;
ld p[n + 1];
rep1(i, n + 1) cin >> p[i];
ld dp[n + 1][n + 1];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
rep1(i, n + 1) {
dp[0][i] = (1 - p[i]) * dp[0][i - 1];
for (ll j = 1; j <= i; j++) {
dp[j][i] = p[i] * dp[j - 1][i - 1] + (1 - p[i]) * dp[j][i - 1];
}
}
ld ans = 0;
for (ll i = n / 2 + 1; i <= n; i++)
ans += dp[i][n];
cout << setprecision(9) << ans << endl;
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t = 1;
// cin>>t;
rep(i, t) solve();
return 0;
} | [
"io.output.change"
] | 977,073 | 977,074 | u035933444 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(), v.end()
#define tc \
int t; \
cin >> t; \
while (t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int, vi, greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g \
int tt; \
cin >> tt; \
for (int ti = 1; ti <= tt; ti++)
#define case_g "Case #" << ti << ": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_map;
int main() {
fast_io;
ll n;
cin >> n;
long double p[n + 1];
long double dp[n + 1][n + 1] = {};
for (int i = 1; i <= n; i++)
cin >> p[i];
dp[0][0] = 1l;
for (int i = 1; i <= n; i++) {
dp[i][0] = (1l - p[i]) * dp[i - 1][0];
for (int j = 1; j <= i; j++) {
dp[i][j] = p[i] * dp[i - 1][j - 1] + (1l - p[i]) * dp[i - 1][j];
}
}
long double ans = 0l;
for (int j = n; j > n / 2; j--)
ans += dp[n][j];
cout << ans << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(), v.end()
#define tc \
int t; \
cin >> t; \
while (t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int, vi, greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g \
int tt; \
cin >> tt; \
for (int ti = 1; ti <= tt; ti++)
#define case_g "Case #" << ti << ": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_map;
int main() {
fast_io;
ll n;
cin >> n;
long double p[n + 1];
long double dp[n + 1][n + 1] = {};
for (int i = 1; i <= n; i++)
cin >> p[i];
dp[0][0] = 1l;
for (int i = 1; i <= n; i++) {
dp[i][0] = (1l - p[i]) * dp[i - 1][0];
for (int j = 1; j <= i; j++) {
dp[i][j] = p[i] * dp[i - 1][j - 1] + (1l - p[i]) * dp[i - 1][j];
}
}
long double ans = 0l;
for (int j = n; j > n / 2; j--)
ans += dp[n][j];
cout << setprecision(10) << ans << '\n';
}
| [
"io.output.change"
] | 977,080 | 977,081 | u059026899 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<double> A(n, 0);
for (int i = 0; i < n; i++)
cin >> A[i];
vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0.0));
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 - A[i - 1]);
} else
dp[i][j] =
dp[i - 1][j] * (1.0 - A[i - 1]) + dp[i - 1][j - 1] * A[i - 1];
}
}
double ans = 0.0;
for (int i = (n + 1) / 2; i <= n; i++) {
ans += dp[n][i];
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<double> A(n, 0);
for (int i = 0; i < n; i++)
cin >> A[i];
vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0.0));
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 - A[i - 1]);
} else
dp[i][j] =
dp[i - 1][j] * (1.0 - A[i - 1]) + dp[i - 1][j - 1] * A[i - 1];
}
}
double ans = 0.0;
for (int i = (n + 1) / 2; i <= n; i++) {
ans += dp[n][i];
}
cout << setprecision(12) << ans << endl;
} | [
"io.output.change"
] | 977,084 | 977,085 | u876488889 | cpp |
p03168 | #include <bits/stdc++.h>
#define ll long long
#define M 1000000007
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, a, b;
cin >> n;
vector<vector<double>> dp(n, vector<double>(n + 1));
vector<double> jp(n);
for (int i = 0; i < n; i++) {
cin >> jp[i];
}
dp[0][0] = (1.0000 - jp[0]), dp[0][1] = jp[0];
for (int i = 1; i < n; i++) {
dp[i][0] = dp[i - 1][0] * (1.0 - jp[i]);
}
for (int i = 1; i < n; i++) { // cout<<"i: ";
for (int j = 1; j <= i + 1; j++) {
dp[i][j] = dp[i - 1][j - 1] * (jp[i]) + dp[i - 1][j] * (1.00 - jp[i]);
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
double sum = 0.00;
for (int i = n / 2 + 1; i <= n; i++) {
sum += dp[n - 1][i];
}
cout << sum;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define M 1000000007
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, a, b;
cin >> n;
vector<vector<double>> dp(n, vector<double>(n + 1));
vector<double> jp(n);
for (int i = 0; i < n; i++) {
cin >> jp[i];
}
dp[0][0] = (1.0000 - jp[0]), dp[0][1] = jp[0];
for (int i = 1; i < n; i++) {
dp[i][0] = dp[i - 1][0] * (1.0 - jp[i]);
}
for (int i = 1; i < n; i++) { // cout<<"i: ";
for (int j = 1; j <= i + 1; j++) {
dp[i][j] = dp[i - 1][j - 1] * (jp[i]) + dp[i - 1][j] * (1.00 - jp[i]);
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
double sum = 0.00;
for (int i = n / 2 + 1; i <= n; i++) {
sum += dp[n - 1][i];
}
cout << setprecision(10) << sum;
return 0;
}
| [
"io.output.change"
] | 977,088 | 977,089 | u213570908 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;
using namespace std;
#define INF ((1 << 30) - 1)
#define LLINF (1LL << 60)
#define EPS (1e-10)
// どういうDPか
// dp[i][j] := i枚目のコインを投げたとき,表がj枚である確率
// 計算方法
// 1-index
// dp[0][0] = 1.0
// dp[i][j] = (dp[i-1][j-1] * p[i] + dp[i-1][j] * (1-p[i]))
// 表が出ることと,出なかったことで場合分け
// どういう順番
// 小さい順から
// j > N-j のときの総和
double dp[3030][3030];
int main() {
int N;
cin >> N;
vector<double> p(N);
rep(i, N) cin >> p[i + 1];
dp[0][0] = 1.0;
for (int i = 1; i <= N; ++i) {
for (int j = 0; j <= N; ++j) {
if (j > 0) {
dp[i][j] += dp[i - 1][j - 1] * p[i];
}
dp[i][j] += dp[i - 1][j] * (1 - p[i]);
// dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1 - p[i]);
}
}
double ans = 0;
for (int i = 0; i <= N; ++i) {
if (i > N - i)
ans += dp[N][i];
}
printf("%.10f\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;
using namespace std;
#define INF ((1 << 30) - 1)
#define LLINF (1LL << 60)
#define EPS (1e-10)
// どういうDPか
// dp[i][j] := i枚目のコインを投げたとき,表がj枚である確率
// 計算方法
// 1-index
// dp[0][0] = 1.0
// dp[i][j] = (dp[i-1][j-1] * p[i] + dp[i-1][j] * (1-p[i]))
// 表が出ることと,出なかったことで場合分け
// どういう順番
// 小さい順から
// j > N-j のときの総和
double dp[3030][3030];
int main() {
int N;
cin >> N;
vector<double> p(N + 1);
rep(i, N) cin >> p[i + 1];
dp[0][0] = 1.0;
for (int i = 1; i <= N; ++i) {
for (int j = 0; j <= N; ++j) {
if (j > 0) {
dp[i][j] += dp[i - 1][j - 1] * p[i];
}
dp[i][j] += dp[i - 1][j] * (1 - p[i]);
// dp[i][j] = dp[i-1][j-1] * p[i] + dp[i-1][j] * (1 - p[i]);
}
}
double ans = 0;
for (int i = 0; i <= N; ++i) {
if (i > N - i)
ans += dp[N][i];
}
printf("%.10f\n", ans);
}
| [
"assignment.change"
] | 977,100 | 977,101 | u482544950 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;
using namespace std;
#define INF ((1 << 30) - 1)
#define LLINF (1LL << 60)
#define EPS (1e-10)
// 分解
// dp[i][j] := i番目までのコインを投げて,表がちょうどj枚になる確率
double dp[3030][3030];
// dp[i][j] = dp[i-1][j-1] * p[j] + dp[i-1][j] * (1-p[j])
// 排反
// i枚目に表が出る確率 dp[i-1][j-1] * p[j]
// i枚目に裏が出る確率 dp[i-1][j] * (1 - p[j])
int main() {
int N;
cin >> N;
vector<double> p(N);
rep(i, N) cin >> p[i + 1];
dp[0][0] = 1.0;
for (int i = 1; i <= N; ++i) {
for (int j = 0; j <= i; ++j) {
if (j - 1 >= 0)
dp[i][j] += dp[i - 1][j - 1] * p[i];
dp[i][j] += dp[i - 1][j] * (1 - p[i]);
}
}
double ans = 0;
for (int i = 0; i <= N; ++i) {
if (i > N - i)
ans += dp[N][i];
}
printf("%.15lf\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i))
using ll = long long;
using namespace std;
#define INF ((1 << 30) - 1)
#define LLINF (1LL << 60)
#define EPS (1e-10)
// 分解
// dp[i][j] := i番目までのコインを投げて,表がちょうどj枚になる確率
double dp[3030][3030];
// dp[i][j] = dp[i-1][j-1] * p[j] + dp[i-1][j] * (1-p[j])
// 排反
// i枚目に表が出る確率 dp[i-1][j-1] * p[j]
// i枚目に裏が出る確率 dp[i-1][j] * (1 - p[j])
int main() {
int N;
cin >> N;
vector<double> p(N + 1);
rep(i, N) cin >> p[i + 1];
dp[0][0] = 1.0;
for (int i = 1; i <= N; ++i) {
for (int j = 0; j <= i; ++j) {
if (j - 1 >= 0)
dp[i][j] += dp[i - 1][j - 1] * p[i];
dp[i][j] += dp[i - 1][j] * (1 - p[i]);
}
}
double ans = 0;
for (int i = 0; i <= N; ++i) {
if (i > N - i)
ans += dp[N][i];
}
printf("%.15lf\n", ans);
}
| [
"assignment.change"
] | 977,102 | 977,103 | u482544950 | cpp |
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][n + 1];
dp[0][0] = 1.0 - p[0];
dp[0][1] = p[0];
for (int i = 2; i < n + 1; i++)
dp[0][i] = 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 < n + 1; j++)
dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
double ans = 0;
for (int i = 0; i < n + 1; i++)
if (i > n - i)
ans += dp[n - 1][i];
cout << ans << endl;
}
| #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][n + 1];
dp[0][0] = 1.0 - p[0];
dp[0][1] = p[0];
for (int i = 2; i < n + 1; i++)
dp[0][i] = 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 < n + 1; j++)
dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
double ans = 0;
for (int i = 0; i < n + 1; i++)
if (i > n - i)
ans += dp[n - 1][i];
cout << setprecision(10) << ans << endl;
}
| [
"io.output.change"
] | 977,116 | 977,117 | u740900993 | cpp |
p03168 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
ll n;
vector<double> p;
void solve() {
// dp[i]: the probability of getting i heads
vector<double> dp1(n + 1);
vector<double> dp2(n + 1);
dp1[0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= n; ++j) {
dp2[j] = dp1[j] * (1 - p[i]);
if (j > 0) {
dp2[j] += dp1[j - 1] * p[i];
}
}
swap(dp1, dp2);
}
double res = 0;
for (int i = (n + 1) / 2; i <= n; ++i) {
res += dp1[i];
}
cout << res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
p = vector<double>(n);
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
solve();
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
ll n;
vector<double> p;
void solve() {
// dp[i]: the probability of getting i heads
vector<double> dp1(n + 1);
vector<double> dp2(n + 1);
dp1[0] = 1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= n; ++j) {
dp2[j] = dp1[j] * (1 - p[i]);
if (j > 0) {
dp2[j] += dp1[j - 1] * p[i];
}
}
swap(dp1, dp2);
}
double res = 0;
for (int i = (n + 1) / 2; i <= n; ++i) {
res += dp1[i];
}
cout << setprecision(10) << res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
p = vector<double>(n);
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
solve();
return 0;
} | [
"io.output.change"
] | 977,118 | 977,119 | u656351541 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
bool vec[3000][3000];
long double res[3000][3000];
long double pro(vector<long double> v, ll n, ll m) {
if (vec[n][m] != 0) {
return vec[n][m];
}
res[1][1] = v[0];
double k = 1;
for (ll i = 1; i <= n; i++) {
k *= (1 - v[i - 1]);
res[i][0] = k;
}
for (ll i = 2; i <= n; i++) {
for (ll j = 1; j <= i; j++) {
res[i][j] = v[i - 1] * res[i - 1][j - 1] + (1 - v[i - 1]) * res[i - 1][j];
}
}
return res[n][m];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a, b, c, d;
long double p;
vector<long double> v;
cin >> a;
for (ll i = 0; i < a; i++) {
cin >> p;
v.push_back(p);
}
ll out = pro(v, a, a);
long double op = 0;
for (ll i = (a + 1) / 2; i <= a; i++) {
op += res[a][i];
}
cout << op;
// cout << pro(v,a,2);
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
bool vec[3000][3000];
long double res[3000][3000];
long double pro(vector<long double> v, ll n, ll m) {
if (vec[n][m] != 0) {
return vec[n][m];
}
res[1][1] = v[0];
double k = 1;
for (ll i = 1; i <= n; i++) {
k *= (1 - v[i - 1]);
res[i][0] = k;
}
for (ll i = 2; i <= n; i++) {
for (ll j = 1; j <= i; j++) {
res[i][j] = v[i - 1] * res[i - 1][j - 1] + (1 - v[i - 1]) * res[i - 1][j];
}
}
return res[n][m];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll a, b, c, d;
long double p;
vector<long double> v;
cin >> a;
for (ll i = 0; i < a; i++) {
cin >> p;
v.push_back(p);
}
ll out = pro(v, a, a);
long double op = 0;
for (ll i = (a + 1) / 2; i <= a; i++) {
op += res[a][i];
}
cout << setprecision(12) << op;
// cout << pro(v,a,2);
} | [
"io.output.change"
] | 977,122 | 977,123 | u454402890 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define sz(v) ((int)((v).size()))
#define ll long long
#define pb push_back
#define fIO \
ios_base::sync_with_stdio(0); \
cin.tie(0);
const ll oo = 1e8;
const double pi = 3.1415926535897;
const double EPS = (1e-8);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
/**
* PLEASEEE READDD PROBLEEEM CARFULLY ****
* Always check for OVERFLOW ll vs int
* Always check for array bounds
* Check for function return
* READ OUTPUT SECTION AGAIN!!!
**/
struct edge {
int from, to, w;
edge() {}
edge(int x, int y, int we) : from(x), to(y), w(we) {}
bool operator<(const edge &rhs) const { return w > rhs.w; }
};
const int N = 2999 + 5;
double dp[N];
double p[N];
int n;
double sol(int i, int hd) {
if (i == n)
return hd >= (n + 1) / 2;
double &ret = dp[i];
if (dcmp(ret, 2.0) != 0)
return ret;
ret = (1 - p[i]) * sol(i + 1, hd);
ret += p[i] * sol(i + 1, hd + 1);
return ret;
}
int main() {
fIO
// freopen("", "r", stdin);
// freopen("", "w", stdout);
for (int i = 0; i < N; i++) dp[i] = 2.0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> p[i];
cout << fixed << setprecision(8) << sol(0, 0) << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define sz(v) ((int)((v).size()))
#define ll long long
#define pb push_back
#define fIO \
ios_base::sync_with_stdio(0); \
cin.tie(0);
const ll oo = 1e8;
const double pi = 3.1415926535897;
const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
/**
* PLEASEEE READDD PROBLEEEM CARFULLY ****
* Always check for OVERFLOW ll vs int
* Always check for array bounds
* Check for function return
* READ OUTPUT SECTION AGAIN!!!
**/
struct edge {
int from, to, w;
edge() {}
edge(int x, int y, int we) : from(x), to(y), w(we) {}
bool operator<(const edge &rhs) const { return w > rhs.w; }
};
const int N = 2999 + 5;
double dp[N][N];
double p[N];
int n;
double sol(int i, int hd) {
if (i == n) {
if (hd > n - hd)
return 1.0;
return 0;
}
double &ret = dp[i][hd];
if (ret < 1.8)
return ret;
ret = (1 - p[i]) * sol(i + 1, hd);
ret += p[i] * sol(i + 1, hd + 1);
return ret;
}
int main() {
fIO
// freopen("", "r", stdin);
// freopen("", "w", stdout);
for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dp[i][j] = 2.0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> p[i];
cout << fixed << setprecision(12) << sol(0, 0) << "\n";
}
| [
"literal.number.change"
] | 977,136 | 977,137 | u294397492 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n;
cin >> n;
double dp[n + 1][n + 1];
double p[n + 1];
for (i = 1; i <= n; i++) {
cin >> p[i];
}
if (n == 1) {
cout << p[1];
return 0;
}
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (i = 1; i <= n; i++) {
for (j = 0; j <= i; j++) {
if (j != 0)
dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
else
dp[i][j] = dp[i - 1][j] * (1 - p[i]);
}
}
double ans = 0;
for (i = (n + 1) / 2; i <= n; i++) {
ans = ans + dp[n][i];
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n;
cin >> n;
double dp[n + 1][n + 1];
double p[n + 1];
for (i = 1; i <= n; i++) {
cin >> p[i];
}
if (n == 1) {
cout << p[1];
return 0;
}
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (i = 1; i <= n; i++) {
for (j = 0; j <= i; j++) {
if (j != 0)
dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
else
dp[i][j] = dp[i - 1][j] * (1 - p[i]);
}
}
double ans = 0;
for (i = (n + 1) / 2; i <= n; i++) {
ans = ans + dp[n][i];
}
cout << setprecision(10) << ans;
}
| [
"io.output.change"
] | 977,146 | 977,147 | u531129785 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
vector<vector<double>> dp(3010, vector<double>(3010, -1));
vector<double> x;
double n, a;
double ans(int curr, int k) {
if (curr == n) {
if (k >= n / 2 + 0.5) {
return 1;
}
return 0;
}
if (dp[curr][k] != -1) {
return dp[curr][k];
}
double ret = 0;
ret += ans(curr + 1, k + 1) * x[curr];
ret += ans(curr + 1, k) * (1 - x[curr]);
dp[curr][k] = ret;
return ret;
}
int main() {
cin >> n;
for (int i = 0; i < n; i += 1) {
cin >> a;
x.push_back(a);
}
cout << setprecision(3) << fixed;
cout << ans(0, 0);
} | #include <bits/stdc++.h>
using namespace std;
vector<vector<double>> dp(3010, vector<double>(3010, -1));
vector<double> x;
double n, a;
double ans(int curr, int k) {
if (curr == n) {
if (k >= n / 2 + 0.5) {
return 1;
}
return 0;
}
if (dp[curr][k] != -1) {
return dp[curr][k];
}
double ret = 0;
ret += ans(curr + 1, k + 1) * x[curr];
ret += ans(curr + 1, k) * (1 - x[curr]);
dp[curr][k] = ret;
return ret;
}
int main() {
cin >> n;
for (int i = 0; i < n; i += 1) {
cin >> a;
x.push_back(a);
}
cout << setprecision(10) << fixed;
cout << ans(0, 0);
} | [
"literal.number.change",
"io.output.change"
] | 977,166 | 977,167 | u689442090 | cpp |
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];
float dp[n + 1][n + 1];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
dp[i][j] = 0.0;
dp[0][0] = 1.0;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= i; j++) {
dp[i][j] = dp[i - 1][j] * p[i - 1];
if (j > 0)
dp[i][j] += (dp[i - 1][j - 1] * (1 - p[i - 1]));
}
float ans = 0.0;
for (int i = 0; 2 * i < n; i++) {
ans += dp[n][i];
}
cout << fixed << setprecision(10) << ans;
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];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
dp[i][j] = 0.0;
dp[0][0] = 1.0;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= i; j++) {
dp[i][j] = dp[i - 1][j] * p[i - 1];
if (j > 0)
dp[i][j] += (dp[i - 1][j - 1] * (1 - p[i - 1]));
}
double ans = 0.0;
for (int i = 0; 2 * i < n; i++) {
ans += dp[n][i];
}
cout << fixed << setprecision(10) << ans;
return 0;
}
| [
"variable_declaration.type.primitive.change"
] | 977,171 | 977,172 | u647025182 | cpp |
p03168 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define R 1000000007
#define M 998244353
int mx = 0, mn = INT32_MAX;
struct maths_util {
vector<long long> fact;
maths_util(int n = 200001, long long q = R) {
fact.resize(n);
fact[0] = 1;
for (int i = 1; i < n; i++)
fact[i] = (fact[i - 1] * i) % q;
}
long long power_mod_q(long long x, long long n, long long q = R) {
if (n == 0)
return 1;
if (n % 2 == 0)
return power_mod_q((x * x) % q, n / 2, q);
else
return (x * power_mod_q((x * x) % q, n / 2, q)) % q;
}
long long inverse_mod_q(long long n, long long q = R) {
return power_mod_q(n, q - 2, q);
}
long long nCr_mod_q(long long n, long long r, long long q = R) {
return (((fact[n] * inverse_mod_q(fact[r], q)) % q) *
inverse_mod_q(fact[n - r], q)) %
q;
}
};
struct dsu {
vector<int> rank, parent;
dsu(int n) {
rank.assign(n, 0);
parent.resize(n);
for (int i = 0; i < n; i++)
parent[i] = i;
}
int find_set(int i) {
if (i == parent[i])
return i;
return parent[i] = find_set(parent[i]);
}
bool is_same_set(int i, int j) {
if (find_set(i) == find_set(j))
return true;
return false;
}
void union_set(int i, int j) {
if (!is_same_set(i, j)) {
int u = find_set(i), v = find_set(j);
if (rank[u] == rank[v]) {
parent[v] = u;
rank[u] += 1;
} else if (rank[u] > rank[v])
parent[v] = u;
else
parent[u] = v;
}
}
};
struct graph {
int v, time, count;
vector<pair<int, int>> *adj;
vector<bool> visited, in_stack, ap;
stack<int> s;
vector<int> color, cc, d, f, l, finish_time, indegree, sccs, topo, outdegree,
pred, child;
graph(int n) {
v = n;
adj = new vector<pair<int, int>>[n];
visited.assign(n, false);
in_stack.assign(n, false);
ap.assign(n, false);
color.assign(n, 0);
cc.assign(n, -1);
d.assign(n, -1);
f.assign(n, -1);
indegree.assign(n, 0);
outdegree.assign(n, 0);
pred.assign(n, -1);
child.assign(n, 0);
time = count = 0;
finish_time.assign(2 * n, -1);
l.assign(n, 0);
}
void add_edge(int u, int v, int w) {
adj[u].push_back(make_pair(v, w));
// adj[v].push_back(make_pair(u, w));
}
void dfs() {
color.assign(v, 0);
cc.assign(v, -1);
time = count = 0;
finish_time.assign(2 * v, -1);
visited.assign(v, false);
pred.assign(v, -1);
for (int i = 0; i < v; i++) {
if (color[i] == 0) {
dfs(i);
count++;
}
}
for (int i = 0; i < v; i++)
finish_time[f[i]] = i;
}
void dfs(int i) {
color[i] = 1;
cc[i] = count;
d[i] = time;
time++;
for (auto x : adj[i])
if (color[x.first] == 0) {
pred[x.first] = i;
dfs(x.first);
}
color[i] = 2;
f[i] = time;
time++;
}
void scc() {
graph g_t(v);
for (int i = 0; i < v; i++)
for (auto x : adj[i])
g_t.add_edge(x.first, i, x.second);
dfs();
for (int i = 2 * v - 1; i >= 0; i--) {
if (finish_time[i] != -1 && g_t.color[finish_time[i]] == 0) {
g_t.dfs(finish_time[i]);
g_t.count++;
}
}
sccs = g_t.cc;
count = g_t.count;
}
void topological_sort() {
for (int i = 0; i < v; i++)
if (adj[i].size())
outdegree[i] = adj[i].size();
for (int i = 0; i < v; i++)
for (auto x : adj[i])
indegree[x.first]++;
vector<int> zero;
for (int i = 0; i < v; i++)
if (!indegree[i])
zero.push_back(i);
while (!zero.empty()) {
int v = zero.back();
topo.push_back(v);
zero.pop_back();
for (auto x : adj[v]) {
indegree[x.first]--;
if (!indegree[x.first])
zero.push_back(x.first);
}
}
}
void tarjan() {
for (int i = 0; i < v; i++)
if (!color[i])
tarjan(i);
}
void tarjan(int i) {
color[i] = 1;
d[i] = time;
time++;
l[i] = d[i];
s.push(i);
in_stack[i] = true;
for (auto x : adj[i]) {
if (!color[x.first]) {
tarjan(x.first);
l[i] = min(l[i], l[x.first]);
} else if (in_stack[x.first]) {
l[i] = min(l[i], d[x.first]);
}
}
color[i] = 2;
f[i] = time;
time++;
if (d[i] == l[i]) {
while (s.top() != i)
cout << s.top() << ' ', in_stack[s.top()] = false, s.pop();
cout << s.top() << '\n', in_stack[s.top()] = false, s.pop();
}
}
void articulate() {
ap.assign(v, false);
color.assign(v, 0);
child.assign(v, 0);
time = 0;
d.assign(v, -1);
f.assign(v, -1);
l.assign(v, 0);
pred.assign(v, -1);
for (int i = 0; i < v; i++)
if (color[i] == 0) {
articulate(i);
if (child[i] == 1 || child[i] == 0)
ap[i] = false;
}
}
void articulate(int i) {
color[i] = 1;
d[i] = time;
time++;
l[i] = d[i];
for (auto x : adj[i]) {
if (pred[i] != x.first && color[x.first] == 1)
l[i] = min(l[i], d[x.first]);
if (!color[x.first]) {
pred[x.first] = i;
child[i]++;
articulate(x.first);
l[i] = min(l[i], l[x.first]);
}
if (l[x.first] >= d[i])
ap[i] = true;
}
f[i] = time;
time++;
color[i] = 2;
}
void bridges() {
time = 0;
f.assign(v, -1);
d.assign(v, -1);
l.assign(v, 0);
color.assign(v, 0);
pred.assign(v, -1);
for (int i = 0; i < v; i++)
if (color[i] == 0)
bridge(i);
}
void bridge(int i) {
color[i] = 1;
d[i] = time;
time++;
l[i] = d[i];
for (auto itr = adj[i].begin(); itr != adj[i].end(); itr++) {
if (pred[i] != itr->first && color[itr->first] == 1)
l[i] = min(l[i], d[itr->first]);
if (!color[itr->first]) {
pred[itr->first] = i;
bridge(itr->first);
l[i] = min(l[i], l[itr->first]);
}
if (l[itr->first] > d[i])
itr->second = 1;
}
color[i] = 2;
f[i] = time;
time++;
}
};
struct kmp {
vector<int> lps;
string p, t;
kmp(string &p, string &t) {
this->p = p;
this->t = t;
// PREPROCESSING
lps.assign(p.size(), 0);
lps[0] = 0;
int len = 0, i = 1, j;
while (i < p.size()) {
if (p[i] == p[len])
lps[i++] = ++len;
else if (len)
len = lps[len - 1];
else
lps[i++] = 0;
}
// STRING MATCHING
i = j = 0;
while (i < t.size()) {
if (p[j] == t[i])
j++, i++;
if (j == p.size())
j = lps[j - 1];
else if (i < t.size() && p[j] != t[i]) {
if (j)
j = lps[j - 1];
else
i++;
}
}
}
};
struct segment_tree {
int n;
vector<int> a;
vector<int> tree;
segment_tree(vector<int> &a) {
n = a.size();
this->a = a;
tree.resize(4 * n);
build(0, 0, n - 1);
}
void build(int node, int l, int r) {
if (l == r)
tree[node] = a[l] = a[r];
else {
int mid = (l + r) / 2;
build(2 * node + 1, l, mid);
build(2 * node + 2, mid + 1, r);
tree[node] = tree[2 * node + 1] + tree[2 * node + 2];
}
}
void update(int node, int l, int r, int i, char x) {
if (l == r) {
a[l] = a[r] = x;
tree[node] = a[l] = a[r];
} else {
int mid = (l + r) / 2;
if (i >= l && i <= mid)
update(2 * node + 1, l, mid, i, x);
else
update(2 * node + 2, mid + 1, r, i, x);
tree[node] = tree[2 * node + 1] + tree[2 * node + 2];
}
}
int query(int node, int l, int r, int s, int e) {
if (l == s && r == e)
return tree[node];
else {
int mid = (s + e) / 2;
if (r <= mid)
return query(2 * node + 1, l, r, s, mid);
else if (l > mid)
return query(2 * node + 2, l, r, mid + 1, e);
else
return query(2 * node + 1, l, mid, s, mid) +
query(2 * node + 2, mid + 1, r, mid + 1, e);
}
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<double> p(n + 1);
for (int i = 1; i <= n; i++)
cin >> p[i];
vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
dp[i][0] = dp[i - 1][0] * p[i];
for (int j = 1; j <= n; j++)
dp[0][j] = dp[0][j - 1] * (1 - p[j]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
dp[i][j] = dp[i - 1][j] * (p[i + j]) + dp[i][j - 1] * (1 - p[i + j]);
}
}
// for(auto x : dp)
// {
// for(auto y : x)
// cout << setw(6) << y << ' ';
// cout << '\n';
// }
double sum = 0;
for (int i = 0; i <= n; i++)
if (i > n - i)
sum += dp[i][n - i];
cout << sum << '\n';
// for(int i = 1; i)
// int k, q;
// cin >> k >> q;
// vector<long long> d(k), d_sum(k);
// for(int i = 0; i < k; i++)
// cin >> d[i];
// d_sum[0] = d[0];
// for(int i = 1; i < k; i++)
// d_sum[i] = d_sum[i-1] + d[i];
// while(q--)
// {
// int n, x, m, z = 0;
// long long ans = 0;
// cin >> n >> x >> m;
// vector<long long> d_mod_m(k), a(k + 1);
// for(int i = 0; i < k; i++)
// d_mod_m[i] = d[i] % m;
// for(int i = 0; i < k; i++)
// if(d_mod_m[i] == 0)
// z++;
// ans = ans + (n / k) * z;
// for(int i = 0; i < (n % k); i++)
// if(d_mod_m[i] == 0)
// ans++;
// a[0] = x % m;
// for(int i = 0; i < k; i++)
// a[i + 1] = (x + d_sum[i]) / m;
// for(int i = 0; i < k; i++)
// cout << d_mod_m[i] << ' ';
// cout << '\n';
// for(auto x : a)
// cout << x << ' ';
// cout << '\n';
// }
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define R 1000000007
#define M 998244353
int mx = 0, mn = INT32_MAX;
struct maths_util {
vector<long long> fact;
maths_util(int n = 200001, long long q = R) {
fact.resize(n);
fact[0] = 1;
for (int i = 1; i < n; i++)
fact[i] = (fact[i - 1] * i) % q;
}
long long power_mod_q(long long x, long long n, long long q = R) {
if (n == 0)
return 1;
if (n % 2 == 0)
return power_mod_q((x * x) % q, n / 2, q);
else
return (x * power_mod_q((x * x) % q, n / 2, q)) % q;
}
long long inverse_mod_q(long long n, long long q = R) {
return power_mod_q(n, q - 2, q);
}
long long nCr_mod_q(long long n, long long r, long long q = R) {
return (((fact[n] * inverse_mod_q(fact[r], q)) % q) *
inverse_mod_q(fact[n - r], q)) %
q;
}
};
struct dsu {
vector<int> rank, parent;
dsu(int n) {
rank.assign(n, 0);
parent.resize(n);
for (int i = 0; i < n; i++)
parent[i] = i;
}
int find_set(int i) {
if (i == parent[i])
return i;
return parent[i] = find_set(parent[i]);
}
bool is_same_set(int i, int j) {
if (find_set(i) == find_set(j))
return true;
return false;
}
void union_set(int i, int j) {
if (!is_same_set(i, j)) {
int u = find_set(i), v = find_set(j);
if (rank[u] == rank[v]) {
parent[v] = u;
rank[u] += 1;
} else if (rank[u] > rank[v])
parent[v] = u;
else
parent[u] = v;
}
}
};
struct graph {
int v, time, count;
vector<pair<int, int>> *adj;
vector<bool> visited, in_stack, ap;
stack<int> s;
vector<int> color, cc, d, f, l, finish_time, indegree, sccs, topo, outdegree,
pred, child;
graph(int n) {
v = n;
adj = new vector<pair<int, int>>[n];
visited.assign(n, false);
in_stack.assign(n, false);
ap.assign(n, false);
color.assign(n, 0);
cc.assign(n, -1);
d.assign(n, -1);
f.assign(n, -1);
indegree.assign(n, 0);
outdegree.assign(n, 0);
pred.assign(n, -1);
child.assign(n, 0);
time = count = 0;
finish_time.assign(2 * n, -1);
l.assign(n, 0);
}
void add_edge(int u, int v, int w) {
adj[u].push_back(make_pair(v, w));
// adj[v].push_back(make_pair(u, w));
}
void dfs() {
color.assign(v, 0);
cc.assign(v, -1);
time = count = 0;
finish_time.assign(2 * v, -1);
visited.assign(v, false);
pred.assign(v, -1);
for (int i = 0; i < v; i++) {
if (color[i] == 0) {
dfs(i);
count++;
}
}
for (int i = 0; i < v; i++)
finish_time[f[i]] = i;
}
void dfs(int i) {
color[i] = 1;
cc[i] = count;
d[i] = time;
time++;
for (auto x : adj[i])
if (color[x.first] == 0) {
pred[x.first] = i;
dfs(x.first);
}
color[i] = 2;
f[i] = time;
time++;
}
void scc() {
graph g_t(v);
for (int i = 0; i < v; i++)
for (auto x : adj[i])
g_t.add_edge(x.first, i, x.second);
dfs();
for (int i = 2 * v - 1; i >= 0; i--) {
if (finish_time[i] != -1 && g_t.color[finish_time[i]] == 0) {
g_t.dfs(finish_time[i]);
g_t.count++;
}
}
sccs = g_t.cc;
count = g_t.count;
}
void topological_sort() {
for (int i = 0; i < v; i++)
if (adj[i].size())
outdegree[i] = adj[i].size();
for (int i = 0; i < v; i++)
for (auto x : adj[i])
indegree[x.first]++;
vector<int> zero;
for (int i = 0; i < v; i++)
if (!indegree[i])
zero.push_back(i);
while (!zero.empty()) {
int v = zero.back();
topo.push_back(v);
zero.pop_back();
for (auto x : adj[v]) {
indegree[x.first]--;
if (!indegree[x.first])
zero.push_back(x.first);
}
}
}
void tarjan() {
for (int i = 0; i < v; i++)
if (!color[i])
tarjan(i);
}
void tarjan(int i) {
color[i] = 1;
d[i] = time;
time++;
l[i] = d[i];
s.push(i);
in_stack[i] = true;
for (auto x : adj[i]) {
if (!color[x.first]) {
tarjan(x.first);
l[i] = min(l[i], l[x.first]);
} else if (in_stack[x.first]) {
l[i] = min(l[i], d[x.first]);
}
}
color[i] = 2;
f[i] = time;
time++;
if (d[i] == l[i]) {
while (s.top() != i)
cout << s.top() << ' ', in_stack[s.top()] = false, s.pop();
cout << s.top() << '\n', in_stack[s.top()] = false, s.pop();
}
}
void articulate() {
ap.assign(v, false);
color.assign(v, 0);
child.assign(v, 0);
time = 0;
d.assign(v, -1);
f.assign(v, -1);
l.assign(v, 0);
pred.assign(v, -1);
for (int i = 0; i < v; i++)
if (color[i] == 0) {
articulate(i);
if (child[i] == 1 || child[i] == 0)
ap[i] = false;
}
}
void articulate(int i) {
color[i] = 1;
d[i] = time;
time++;
l[i] = d[i];
for (auto x : adj[i]) {
if (pred[i] != x.first && color[x.first] == 1)
l[i] = min(l[i], d[x.first]);
if (!color[x.first]) {
pred[x.first] = i;
child[i]++;
articulate(x.first);
l[i] = min(l[i], l[x.first]);
}
if (l[x.first] >= d[i])
ap[i] = true;
}
f[i] = time;
time++;
color[i] = 2;
}
void bridges() {
time = 0;
f.assign(v, -1);
d.assign(v, -1);
l.assign(v, 0);
color.assign(v, 0);
pred.assign(v, -1);
for (int i = 0; i < v; i++)
if (color[i] == 0)
bridge(i);
}
void bridge(int i) {
color[i] = 1;
d[i] = time;
time++;
l[i] = d[i];
for (auto itr = adj[i].begin(); itr != adj[i].end(); itr++) {
if (pred[i] != itr->first && color[itr->first] == 1)
l[i] = min(l[i], d[itr->first]);
if (!color[itr->first]) {
pred[itr->first] = i;
bridge(itr->first);
l[i] = min(l[i], l[itr->first]);
}
if (l[itr->first] > d[i])
itr->second = 1;
}
color[i] = 2;
f[i] = time;
time++;
}
};
struct kmp {
vector<int> lps;
string p, t;
kmp(string &p, string &t) {
this->p = p;
this->t = t;
// PREPROCESSING
lps.assign(p.size(), 0);
lps[0] = 0;
int len = 0, i = 1, j;
while (i < p.size()) {
if (p[i] == p[len])
lps[i++] = ++len;
else if (len)
len = lps[len - 1];
else
lps[i++] = 0;
}
// STRING MATCHING
i = j = 0;
while (i < t.size()) {
if (p[j] == t[i])
j++, i++;
if (j == p.size())
j = lps[j - 1];
else if (i < t.size() && p[j] != t[i]) {
if (j)
j = lps[j - 1];
else
i++;
}
}
}
};
struct segment_tree {
int n;
vector<int> a;
vector<int> tree;
segment_tree(vector<int> &a) {
n = a.size();
this->a = a;
tree.resize(4 * n);
build(0, 0, n - 1);
}
void build(int node, int l, int r) {
if (l == r)
tree[node] = a[l] = a[r];
else {
int mid = (l + r) / 2;
build(2 * node + 1, l, mid);
build(2 * node + 2, mid + 1, r);
tree[node] = tree[2 * node + 1] + tree[2 * node + 2];
}
}
void update(int node, int l, int r, int i, char x) {
if (l == r) {
a[l] = a[r] = x;
tree[node] = a[l] = a[r];
} else {
int mid = (l + r) / 2;
if (i >= l && i <= mid)
update(2 * node + 1, l, mid, i, x);
else
update(2 * node + 2, mid + 1, r, i, x);
tree[node] = tree[2 * node + 1] + tree[2 * node + 2];
}
}
int query(int node, int l, int r, int s, int e) {
if (l == s && r == e)
return tree[node];
else {
int mid = (s + e) / 2;
if (r <= mid)
return query(2 * node + 1, l, r, s, mid);
else if (l > mid)
return query(2 * node + 2, l, r, mid + 1, e);
else
return query(2 * node + 1, l, mid, s, mid) +
query(2 * node + 2, mid + 1, r, mid + 1, e);
}
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<double> p(n + 1);
for (int i = 1; i <= n; i++)
cin >> p[i];
vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
dp[i][0] = dp[i - 1][0] * p[i];
for (int j = 1; j <= n; j++)
dp[0][j] = dp[0][j - 1] * (1 - p[j]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
dp[i][j] = dp[i - 1][j] * (p[i + j]) + dp[i][j - 1] * (1 - p[i + j]);
}
}
// for(auto x : dp)
// {
// for(auto y : x)
// cout << setw(6) << y << ' ';
// cout << '\n';
// }
double sum = 0;
for (int i = 0; i <= n; i++)
if (i > n - i)
sum += dp[i][n - i];
cout << setprecision(10) << sum << '\n';
// for(int i = 1; i)
// int k, q;
// cin >> k >> q;
// vector<long long> d(k), d_sum(k);
// for(int i = 0; i < k; i++)
// cin >> d[i];
// d_sum[0] = d[0];
// for(int i = 1; i < k; i++)
// d_sum[i] = d_sum[i-1] + d[i];
// while(q--)
// {
// int n, x, m, z = 0;
// long long ans = 0;
// cin >> n >> x >> m;
// vector<long long> d_mod_m(k), a(k + 1);
// for(int i = 0; i < k; i++)
// d_mod_m[i] = d[i] % m;
// for(int i = 0; i < k; i++)
// if(d_mod_m[i] == 0)
// z++;
// ans = ans + (n / k) * z;
// for(int i = 0; i < (n % k); i++)
// if(d_mod_m[i] == 0)
// ans++;
// a[0] = x % m;
// for(int i = 0; i < k; i++)
// a[i + 1] = (x + d_sum[i]) / m;
// for(int i = 0; i < k; i++)
// cout << d_mod_m[i] << ' ';
// cout << '\n';
// for(auto x : a)
// cout << x << ' ';
// cout << '\n';
// }
return 0;
} | [
"io.output.change"
] | 977,173 | 977,174 | u786837146 | cpp |
p03168 | #include <bits/stdc++.h>
#define LL long long int
#define Max(x, y) (x > y ? x : y)
#define Min(x, y) (x < y ? x : y)
#define Abs(x) ((x) > 0 ? (x) : -(x))
#define Swap(x, y) \
do { \
x = x ^ y; \
y = x ^ y; \
x = x ^ y; \
} while (0)
#define IO_BOOST \
ios_base::sync_with_stdio(false); \
cin.tie(0)
#define setp(x) fixed << setprecision(x)
#define INF 0x3f3f3f3f
#define Lowbit(x) ((x) & (-x))
#define Pii pair<int, int>
#define x first
#define y second
#define MOD ((int)1e9 + 7)
using namespace std;
int n, m;
long double pr[3000];
long double dp[3000];
void forkdp(long double *temp, long double *dp) {
for (int i = 0; i <= n; i++)
temp[i] = dp[i];
}
void solve() {
dp[0] = 1;
for (int i = 1; i <= n; i++) {
long double temp[3000];
forkdp(temp, dp);
for (int j = 1; j <= i; j++) {
dp[j] = temp[j - 1] * pr[i] + temp[j] * (1 - pr[i]);
}
dp[0] *= (1 - pr[i]);
}
long double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[i];
}
cout << ans << '\n';
}
int main() {
IO_BOOST;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> pr[i];
solve();
} | #include <bits/stdc++.h>
#define LL long long int
#define Max(x, y) (x > y ? x : y)
#define Min(x, y) (x < y ? x : y)
#define Abs(x) ((x) > 0 ? (x) : -(x))
#define Swap(x, y) \
do { \
x = x ^ y; \
y = x ^ y; \
x = x ^ y; \
} while (0)
#define IO_BOOST \
ios_base::sync_with_stdio(false); \
cin.tie(0)
#define setp(x) fixed << setprecision(x)
#define INF 0x3f3f3f3f
#define Lowbit(x) ((x) & (-x))
#define Pii pair<int, int>
#define x first
#define y second
#define MOD ((int)1e9 + 7)
using namespace std;
int n, m;
long double pr[3000];
long double dp[3000];
void forkdp(long double *temp, long double *dp) {
for (int i = 0; i <= n; i++)
temp[i] = dp[i];
}
void solve() {
dp[0] = 1;
for (int i = 1; i <= n; i++) {
long double temp[3000];
forkdp(temp, dp);
for (int j = 1; j <= i; j++) {
dp[j] = temp[j - 1] * pr[i] + temp[j] * (1 - pr[i]);
}
dp[0] *= (1 - pr[i]);
}
long double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[i];
}
cout << setp(10) << ans << '\n';
}
int main() {
IO_BOOST;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> pr[i];
solve();
} | [
"io.output.change"
] | 977,178 | 977,179 | u369631563 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, f, e) for (int(i) = (f); (i) < (e); (i)++)
#define repr(i, e, f) for (int(i) = (e - 1); (i) >= (f); (i)--)
const ll MOD = 1e9 + 7;
const int INF = (int)1e9 + 7;
// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
// for( int i = 0; i < N; i++ ){
// cin >> v >> w;
// items.push_back( make_tuple(v, w) ); // item : (value, weight)
// }
double dp[3001][3001];
int main() {
int N;
cin >> N;
double p;
cin >> p;
dp[1][0] = 1.0 - p;
dp[1][1] = p;
rep(i, 2, N + 1) {
cin >> p;
dp[i][0] = dp[i - 1][0] * (1.0 - p);
rep(j, 1, N + 1) {
dp[i][j] = dp[i - 1][j] * (1.0 - p) + dp[i - 1][j - 1] * p;
}
}
// rep(j, 0, N+1){
// cout << j << "/" << N << " : " << dp[N][j] << endl;
// }
double ans = 0.0;
rep(j, (N + 1) / 2, N + 1) { ans += dp[N][j]; }
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, f, e) for (int(i) = (f); (i) < (e); (i)++)
#define repr(i, e, f) for (int(i) = (e - 1); (i) >= (f); (i)--)
const ll MOD = 1e9 + 7;
const int INF = (int)1e9 + 7;
// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
// for( int i = 0; i < N; i++ ){
// cin >> v >> w;
// items.push_back( make_tuple(v, w) ); // item : (value, weight)
// }
double dp[3001][3001];
int main() {
int N;
cin >> N;
double p;
cin >> p;
dp[1][0] = 1.0 - p;
dp[1][1] = p;
rep(i, 2, N + 1) {
cin >> p;
dp[i][0] = dp[i - 1][0] * (1.0 - p);
rep(j, 1, N + 1) {
dp[i][j] = dp[i - 1][j] * (1.0 - p) + dp[i - 1][j - 1] * p;
}
}
// rep(j, 0, N+1){
// cout << j << "/" << N << " : " << dp[N][j] << endl;
// }
double ans = 0.0;
rep(j, (N + 1) / 2, N + 1) { ans += dp[N][j]; }
cout << setprecision(10) << ans;
return 0;
}
| [
"io.output.change"
] | 977,182 | 977,183 | u068277996 | cpp |
p03168 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
// constexpr ll MOD = (998244353);
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
ll maxVec(vector<ll> &v) {
ll ans = -INF;
rep(i, v.size()) { ans = max(ans, v[i]); }
return ans;
}
int main() {
ll n;
cin >> n;
vector<long double> p(n, 0);
vector<vector<long double>> dp(n + 1, vector<long double>(n + 1, 0));
rep(i, n) { cin >> p[i]; }
dp[0][0] = 1;
/*
rep(i, n + 1) {
if (i == 0)continue;
rep(j, n + 1) {
dp[i][j] += dp[i - 1][j] * (1 - p[i - 1]);
if (j - 1 >= 0)dp[i][j] += dp[i - 1][j - 1] * p[i - 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.0 - p[i]);
}
}
/*
rep(i, n + 1) {
rep(j, n + 1) {
cout << dp[i][j] << " ";
}
cout << "\n";
}
*/
long double ans = 0;
for (ll i = (n + 1) / 2; i < n + 1; i++) {
ans += dp[n][i];
}
printf("%.10g", ans);
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
// constexpr ll MOD = (998244353);
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
ll maxVec(vector<ll> &v) {
ll ans = -INF;
rep(i, v.size()) { ans = max(ans, v[i]); }
return ans;
}
int main() {
ll n;
cin >> n;
vector<double> p(n, 0);
vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
rep(i, n) { cin >> p[i]; }
dp[0][0] = 1;
/*
rep(i, n + 1) {
if (i == 0)continue;
rep(j, n + 1) {
dp[i][j] += dp[i - 1][j] * (1 - p[i - 1]);
if (j - 1 >= 0)dp[i][j] += dp[i - 1][j - 1] * p[i - 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.0 - p[i]);
}
}
/*
rep(i, n + 1) {
rep(j, n + 1) {
cout << dp[i][j] << " ";
}
cout << "\n";
}
*/
double ans = 0;
for (ll i = (n + 1) / 2; i < n + 1; i++) {
ans += dp[n][i];
}
printf("%.10g", ans);
} | [
"variable_declaration.type.narrow.change"
] | 977,192 | 977,193 | u924406834 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1000000007;
int main() {
ll n, i, j;
cin >> n;
double p[n];
for (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 += 1) {
for (int j = 0; j <= i; j += 1) {
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 ans = 0.0;
for (int i = (n + 1) / 2; i <= n; i += 1)
ans += dp[n][i];
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1000000007;
int main() {
ll n, i, j;
cin >> n;
double p[n];
for (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 += 1) {
for (int j = 0; j <= i; j += 1) {
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 ans = 0.0;
for (int i = (n + 1) / 2; i <= n; i += 1)
ans += dp[n][i];
cout << setprecision(12) << ans;
}
| [
"io.output.change"
] | 977,194 | 977,195 | u919005705 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// head
const int mxN = 5e3;
int n;
// dp[i][j]: There are i heads coin among the first j coins
// dp[i][j] += dp[i-1][j-1] * p[j] + dp[i][j-1] * (1-p[j]);
double p[mxN], dp[mxN][mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
rep(i, 0, n) cin >> p[i + 1];
dp[0][0] = 1.0;
// All heads
rep(i, 1, n + 1) dp[i][i] = p[i] * dp[i - 1][i - 1];
// All tails
rep(i, 1, n + 1) dp[0][i] = (1 - p[i]) * dp[0][i - 1];
rep(j, 1, n + 1) {
rep(i, 1, j) {
dp[i][j] += dp[i - 1][j - 1] * p[j] + dp[i][j - 1] * (1 - p[j]);
}
}
double ans = 0;
rep(i, n / 2 + 1, n + 1) ans += dp[i][n];
printf("%.10.f\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// head
const int mxN = 5e3;
int n;
// dp[i][j]: There are i heads coin among the first j coins
// dp[i][j] += dp[i-1][j-1] * p[j] + dp[i][j-1] * (1-p[j]);
double p[mxN], dp[mxN][mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
rep(i, 0, n) cin >> p[i + 1];
dp[0][0] = 1.0;
// All heads
rep(i, 1, n + 1) dp[i][i] = p[i] * dp[i - 1][i - 1];
// All tails
rep(i, 1, n + 1) dp[0][i] = (1 - p[i]) * dp[0][i - 1];
rep(j, 1, n + 1) {
rep(i, 1, j) {
dp[i][j] += dp[i - 1][j - 1] * p[j] + dp[i][j - 1] * (1 - p[j]);
}
}
double ans = 0;
rep(i, n / 2 + 1, n + 1) ans += dp[i][n];
printf("%.10lf\n", ans);
}
| [
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 977,196 | 977,197 | u452819435 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// head
const int mxN = 3e3;
int n;
// dp[i][j]: There are i heads coin among the first j coins
// dp[i][j] += dp[i-1][j-1] * p[j] + dp[i][j-1] * (1-p[j]);
double p[mxN], dp[mxN][mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
rep(i, 0, n) cin >> p[i + 1];
dp[0][0] = 1.0;
// All heads
rep(i, 1, n + 1) dp[i][i] = p[i] * dp[i - 1][i - 1];
// All tails
rep(i, 1, n + 1) dp[0][i] = (1 - p[i]) * dp[0][i - 1];
rep(j, 1, n + 1) {
rep(i, 1, j) {
dp[i][j] += dp[i - 1][j - 1] * p[j] + dp[i][j - 1] * (1 - p[j]);
}
}
double ans = 0;
rep(i, n / 2 + 1, n + 1) ans += dp[i][n];
printf("%.10.f\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// head
const int mxN = 5e3;
int n;
// dp[i][j]: There are i heads coin among the first j coins
// dp[i][j] += dp[i-1][j-1] * p[j] + dp[i][j-1] * (1-p[j]);
double p[mxN], dp[mxN][mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
rep(i, 0, n) cin >> p[i + 1];
dp[0][0] = 1.0;
// All heads
rep(i, 1, n + 1) dp[i][i] = p[i] * dp[i - 1][i - 1];
// All tails
rep(i, 1, n + 1) dp[0][i] = (1 - p[i]) * dp[0][i - 1];
rep(j, 1, n + 1) {
rep(i, 1, j) {
dp[i][j] += dp[i - 1][j - 1] * p[j] + dp[i][j - 1] * (1 - p[j]);
}
}
double ans = 0;
rep(i, n / 2 + 1, n + 1) ans += dp[i][n];
printf("%.10lf\n", ans);
}
| [
"literal.number.change",
"variable_declaration.value.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 977,198 | 977,197 | u452819435 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// head
const int mxN = 3e3;
int n;
// dp[i][j]: There are i heads coin among the first j coins
// dp[i][j] += dp[i-1][j-1] * p[j] + dp[i][j-1] * (1-p[j])
// dp[i-1][j] += dp[i-1][j-1] * (1-p[j]) + dp[i-2][j-1] * p[j]
double p[mxN], dp[mxN][mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
rep(i, 0, n) cin >> p[i + 1];
dp[0][0] = 1.0;
// All heads
rep(i, 1, n + 1) dp[i][i] = p[i] * dp[i - 1][i - 1];
// All tails
rep(i, 1, n + 1) dp[0][i] = (1 - p[i]) * dp[0][i - 1];
rep(j, 1, n + 1) {
rep(i, 1, j) {
dp[i][j] += dp[i - 1][j - 1] * p[j] + dp[i][j - 1] * (1 - p[j]);
}
}
double ans = 0;
rep(i, n / 2 + 1, n + 1) ans += dp[i][n];
printf("%.10.f\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// head
const int mxN = 5e3;
int n;
// dp[i][j]: There are i heads coin among the first j coins
// dp[i][j] += dp[i-1][j-1] * p[j] + dp[i][j-1] * (1-p[j]);
double p[mxN], dp[mxN][mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
rep(i, 0, n) cin >> p[i + 1];
dp[0][0] = 1.0;
// All heads
rep(i, 1, n + 1) dp[i][i] = p[i] * dp[i - 1][i - 1];
// All tails
rep(i, 1, n + 1) dp[0][i] = (1 - p[i]) * dp[0][i - 1];
rep(j, 1, n + 1) {
rep(i, 1, j) {
dp[i][j] += dp[i - 1][j - 1] * p[j] + dp[i][j - 1] * (1 - p[j]);
}
}
double ans = 0;
rep(i, n / 2 + 1, n + 1) ans += dp[i][n];
printf("%.10lf\n", ans);
}
| [
"literal.number.change",
"variable_declaration.value.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 977,199 | 977,197 | u452819435 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i, a, b) for (int i = (a); i < (b); i++)
#define frr(i, a, b) for (int i = (a - 1); i >= (b); i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll, ll>
#define rev(a) reverse(a.begin(), a.end())
#define srt(a) sort(a.begin(), a.end())
#define rsrt(a) sort(a.begin(), a.end(), greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
ll M = 1e9 + 7;
int n;
double a[3001];
double dp[3001][3001];
int ready[3001][3001];
double solve(int ind, int num) {
if (ready[ind][num])
return dp[ind][num];
if (ind == 0) {
return 0.0;
}
if (num == 0)
return (1 - a[ind]) * solve(ind - 1, num);
ready[ind][num] = 1;
return dp[ind][num] = a[ind] * solve(ind - 1, num - 1) +
(1.0 - a[ind]) * solve(ind - 1, num);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
//#endif
cin >> n;
fr(i, 1, n + 1) cin >> a[i];
memset(ready, 0, sizeof ready);
fr(i, 0, 3001) fr(j, 0, 3001) dp[i][j] = 0.0;
ready[0][0] = 1;
dp[0][0] = 1.0;
double ans = 0;
fr(i, 0, n + 1) {
if (i > n / 2)
ans += solve(n, i);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i, a, b) for (int i = (a); i < (b); i++)
#define frr(i, a, b) for (int i = (a - 1); i >= (b); i--)
#define vi vector<int>
#define de deque<int>
#define del deque<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define mp map<ll, ll>
#define rev(a) reverse(a.begin(), a.end())
#define srt(a) sort(a.begin(), a.end())
#define rsrt(a) sort(a.begin(), a.end(), greater<int>())
#define ln(a) a.length()
#define sz(a) a.size()
ll M = 1e9 + 7;
int n;
double a[3001];
double dp[3001][3001];
int ready[3001][3001];
double solve(int ind, int num) {
if (ready[ind][num])
return dp[ind][num];
if (ind == 0) {
return 0.0;
}
if (num == 0)
return (1 - a[ind]) * solve(ind - 1, num);
ready[ind][num] = 1;
return dp[ind][num] = a[ind] * solve(ind - 1, num - 1) +
(1.0 - a[ind]) * solve(ind - 1, num);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//#ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
//#endif
cin >> n;
fr(i, 1, n + 1) cin >> a[i];
memset(ready, 0, sizeof ready);
fr(i, 0, 3001) fr(j, 0, 3001) dp[i][j] = 0.0;
ready[0][0] = 1;
dp[0][0] = 1.0;
double ans = 0;
fr(i, 0, n + 1) {
if (i > n / 2)
ans += solve(n, i);
}
cout << setprecision(12) << ans << endl;
} | [
"io.output.change"
] | 977,202 | 977,203 | u616159561 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
int main() {
double n;
scanf("%lf", &n);
vector<double> dp(n + 1);
dp[0] = 1;
for (int i = 0; i < n; i++) {
double r;
scanf("%lf", &r);
for (int j = i + 1; j >= 0; j--) {
dp[j] = (j == 0 ? 0 : dp[j - 1] * (r)) + dp[j] * (1 - r);
}
}
double result = 0;
for (int i = n / 2 + 1; i <= n; i++)
result += dp[i];
printf("%10.lf\n", result);
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<double> dp(n + 1);
dp[0] = 1;
for (int i = 0; i < n; i++) {
double r;
scanf("%lf", &r);
for (int j = i + 1; j >= 0; j--) {
dp[j] = (j == 0 ? 0 : dp[j - 1] * (r)) + dp[j] * (1 - r);
}
}
double result = 0;
for (int i = n / 2 + 1; i <= n; i++)
result += dp[i];
printf("%.10lf\n", result);
} | [
"variable_declaration.type.primitive.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 977,223 | 977,222 | u129437649 | cpp |
p03168 | #include <bits/stdc++.h>
#define loop(x) for (int i = 0; i < x; i++)
#define deb(x) cout << #x << x << " "
#define ll long long
#define LINF 1e18L + 5
#define INF 1e9 + 7
using namespace std;
const int max_size = 1e5 + 5;
int totalMax = 0;
int maxAmount = -400;
vector<int> visited(max_size, 0);
vector<int> maxLength(max_size, 0);
vector<int> incom(max_size, 0);
bool f(string s1) {}
void dfs(vector<vector<int>> arr, int i) {
if (visited[i]) {
return;
}
visited[i] = true;
for (int j = 0; j < arr[i].size(); j++) {
incom[arr[i][j]]--;
maxLength[arr[i][j]] = max(maxLength[arr[i][j]], maxLength[i] + 1);
if (incom[arr[i][j]] == 0) {
dfs(arr, arr[i][j]);
}
}
}
int main() {
int t = 1;
// cin>>t;
while (t--) {
// FOR ARRAY
// int n;
// cin>>n;
// vector<int> arr;
// for(int i = 0; i < n; i++) {
// int x;
// cin>>x;
// arr.push_back(x);
// }
// f(arr);
// FOR MATRIX
// int row, col;
// cin>>row;
// cin>>col;
// vector<vector<int>> arr(row, vector<int>(col, 0));
// for(int i = 0; i < row; i++) {
// for(int j = 0; j < col; j++) {
// cin>>arr[i][j];
// }
// }
int n;
cin >> n;
vector<double> p(n, 0);
for (int i = 0; i < n; i++) {
cin >> p[i];
}
vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
for (int i = 0; i <= n / 2 + 1; i++) {
for (int j = 0; j <= n; j++) {
if (i == 0 && j == 0) {
dp[i][j] = 1;
} else if (j == 0) {
dp[i][j] = 0;
} else if (i == 0) {
dp[i][j] = 1;
} else {
dp[i][j] = (double)p[j - 1] * dp[i - 1][j - 1] +
(double)((double)1 - p[j - 1]) * dp[i][j - 1];
}
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
cout << dp[n / 2 + 1][n] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define loop(x) for (int i = 0; i < x; i++)
#define deb(x) cout << #x << x << " "
#define ll long long
#define LINF 1e18L + 5
#define INF 1e9 + 7
using namespace std;
const int max_size = 1e5 + 5;
int totalMax = 0;
int maxAmount = -400;
vector<int> visited(max_size, 0);
vector<int> maxLength(max_size, 0);
vector<int> incom(max_size, 0);
bool f(string s1) {}
void dfs(vector<vector<int>> arr, int i) {
if (visited[i]) {
return;
}
visited[i] = true;
for (int j = 0; j < arr[i].size(); j++) {
incom[arr[i][j]]--;
maxLength[arr[i][j]] = max(maxLength[arr[i][j]], maxLength[i] + 1);
if (incom[arr[i][j]] == 0) {
dfs(arr, arr[i][j]);
}
}
}
int main() {
int t = 1;
// cin>>t;
while (t--) {
// FOR ARRAY
// int n;
// cin>>n;
// vector<int> arr;
// for(int i = 0; i < n; i++) {
// int x;
// cin>>x;
// arr.push_back(x);
// }
// f(arr);
// FOR MATRIX
// int row, col;
// cin>>row;
// cin>>col;
// vector<vector<int>> arr(row, vector<int>(col, 0));
// for(int i = 0; i < row; i++) {
// for(int j = 0; j < col; j++) {
// cin>>arr[i][j];
// }
// }
int n;
cin >> n;
vector<double> p(n, 0);
for (int i = 0; i < n; i++) {
cin >> p[i];
}
vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
for (int i = 0; i <= n / 2 + 1; i++) {
for (int j = 0; j <= n; j++) {
if (i == 0 && j == 0) {
dp[i][j] = 1;
} else if (j == 0) {
dp[i][j] = 0;
} else if (i == 0) {
dp[i][j] = 1;
} else {
dp[i][j] = (double)p[j - 1] * dp[i - 1][j - 1] +
(double)((double)1 - p[j - 1]) * dp[i][j - 1];
}
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
cout << setprecision(10) << dp[n / 2 + 1][n] << endl;
}
return 0;
}
| [
"io.output.change"
] | 977,229 | 977,230 | u698912407 | cpp |
p03168 | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define double long double
using datas = pair<ll, ll>;
using ddatas = pair<double, double>;
using tdata = pair<ll, datas>;
using vec = vector<ll>;
using mat = vector<vec>;
using pvec = vector<datas>;
using pmat = vector<pvec>;
#define For(i, a, b) for (i = a; i < (ll)b; i++)
#define bFor(i, a, b) for (i = a; i >= (ll)b; i--)
#define rep(i, N) For(i, 0, N)
#define rep1(i, N) For(i, 1, N)
#define brep(i, N) bFor(i, N - 1, 0)
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout << v << endl
#define printyes cout << "Yes" << endl
#define printno cout << "No" << endl
#define printYES cout << "YES" << endl
#define printNO cout << "NO" << endl
#define output(v) \
do { \
bool f = 0; \
for (auto outi : v) { \
cout << (f ? " " : "") << outi; \
f = 1; \
} \
cout << endl; \
} while (0)
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const double PI = acos(-1);
const double eps = 1e-9;
template <class T> inline bool chmax(T &a, T b) {
bool x = a < b;
if (x)
a = b;
return x;
}
template <class T> inline bool chmin(T &a, T b) {
bool x = a > b;
if (x)
a = b;
return x;
}
void startupcpp() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
double distance(ddatas x, ddatas y) {
double a = x.first - y.first, b = x.second - y.second;
return sqrt(a * a + b * b);
}
ll modinv(ll a) {
ll b = mod, u = 1, v = 0, t;
while (b) {
t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
return (u + mod) % mod;
}
ll moddevide(ll a, ll b) { return (a * modinv(b)) % mod; }
vec modncrlistp, modncrlistm;
ll modncr(ll n, ll r) {
ll i, size = modncrlistp.size();
if (size <= n) {
modncrlistp.resize(n + 1);
modncrlistm.resize(n + 1);
if (!size) {
modncrlistp[0] = modncrlistm[0] = 1;
size++;
}
For(i, size, n + 1) {
modncrlistp[i] = modncrlistp[i - 1] * i % mod;
modncrlistm[i] = modinv(modncrlistp[i]);
}
}
return modncrlistp[n] * modncrlistm[r] % mod * modncrlistm[n - r] % mod;
}
ll modpow(ll a, ll n) {
ll res = 1;
while (n) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
ll gcd(ll a, ll b) {
if (!b)
return a;
return (a % b == 0) ? b : gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countdigits(ll n) {
ll ans = 0;
while (n) {
n /= 10;
ans++;
}
return ans;
}
ll sumdigits(ll n) {
ll ans = 0;
while (n) {
ans += n % 10;
n /= 10;
}
return ans;
}
int main() {
startupcpp();
// ll test;cin>>test;while(test--){
ll i, j, N;
cin >> N;
double x;
vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0));
dp[0][0] = 1;
rep1(i, N + 1) {
cin >> x;
rep(j, i) {
dp[i][j] += dp[i - 1][j] * (1 - x);
dp[i][j + 1] += dp[i - 1][j] * x;
}
}
x = 0;
For(i, N / 2 + 1, N) { x += dp[N][i]; }
cout << x << endl;
return 0;
} | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define double long double
using datas = pair<ll, ll>;
using ddatas = pair<double, double>;
using tdata = pair<ll, datas>;
using vec = vector<ll>;
using mat = vector<vec>;
using pvec = vector<datas>;
using pmat = vector<pvec>;
#define For(i, a, b) for (i = a; i < (ll)b; i++)
#define bFor(i, a, b) for (i = a; i >= (ll)b; i--)
#define rep(i, N) For(i, 0, N)
#define rep1(i, N) For(i, 1, N)
#define brep(i, N) bFor(i, N - 1, 0)
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout << v << endl
#define printyes cout << "Yes" << endl
#define printno cout << "No" << endl
#define printYES cout << "YES" << endl
#define printNO cout << "NO" << endl
#define output(v) \
do { \
bool f = 0; \
for (auto outi : v) { \
cout << (f ? " " : "") << outi; \
f = 1; \
} \
cout << endl; \
} while (0)
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const double PI = acos(-1);
const double eps = 1e-9;
template <class T> inline bool chmax(T &a, T b) {
bool x = a < b;
if (x)
a = b;
return x;
}
template <class T> inline bool chmin(T &a, T b) {
bool x = a > b;
if (x)
a = b;
return x;
}
void startupcpp() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
double distance(ddatas x, ddatas y) {
double a = x.first - y.first, b = x.second - y.second;
return sqrt(a * a + b * b);
}
ll modinv(ll a) {
ll b = mod, u = 1, v = 0, t;
while (b) {
t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
return (u + mod) % mod;
}
ll moddevide(ll a, ll b) { return (a * modinv(b)) % mod; }
vec modncrlistp, modncrlistm;
ll modncr(ll n, ll r) {
ll i, size = modncrlistp.size();
if (size <= n) {
modncrlistp.resize(n + 1);
modncrlistm.resize(n + 1);
if (!size) {
modncrlistp[0] = modncrlistm[0] = 1;
size++;
}
For(i, size, n + 1) {
modncrlistp[i] = modncrlistp[i - 1] * i % mod;
modncrlistm[i] = modinv(modncrlistp[i]);
}
}
return modncrlistp[n] * modncrlistm[r] % mod * modncrlistm[n - r] % mod;
}
ll modpow(ll a, ll n) {
ll res = 1;
while (n) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
ll gcd(ll a, ll b) {
if (!b)
return a;
return (a % b == 0) ? b : gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countdigits(ll n) {
ll ans = 0;
while (n) {
n /= 10;
ans++;
}
return ans;
}
ll sumdigits(ll n) {
ll ans = 0;
while (n) {
ans += n % 10;
n /= 10;
}
return ans;
}
int main() {
startupcpp();
// ll test;cin>>test;while(test--){
ll i, j, N;
cin >> N;
double x;
vector<vector<double>> dp(N + 1, vector<double>(N + 1, 0));
dp[0][0] = 1;
rep1(i, N + 1) {
cin >> x;
rep(j, i) {
dp[i][j] += dp[i - 1][j] * (1 - x);
dp[i][j + 1] += dp[i - 1][j] * x;
}
}
x = 0;
For(i, N / 2 + 1, N + 1) { x += dp[N][i]; }
cout << x << endl;
return 0;
} | [
"expression.operation.binary.add"
] | 977,231 | 977,232 | u251847465 | cpp |
p03168 | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define pb push_back
#define ins insert
#define pob pop_back
#define er erase
#define emp empty
#define f first
#define s second
#define ff f.f
#define fs f.s
#define sf s.f
#define ss s.s
#define var auto
using namespace std;
template <typename T> using s = set<T>;
template <typename T> using v = vector<T>;
template <typename T1, typename T2> using p = pair<T1, T2>;
typedef long long ll;
typedef p<int, int> pii;
typedef v<int> vi;
typedef v<pii> vpii;
typedef s<int> si;
typedef s<pii> spii;
const int Max = 4e3 + 100;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
int n;
double dp[Max][Max];
double A[Max];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> A[i];
dp[0][0] = 1 - A[0];
dp[0][1] = A[0];
for (int i = 1; i < n; i++) {
for (int j = 0; j <= i + 1; j++) {
if (j > 0)
dp[i][j] = dp[i - 1][j - 1] * A[i] + dp[i - 1][j] * (1 - A[i]);
else
dp[i][j] = dp[i - 1][j] * (1 - A[i]);
}
}
double res = 0;
for (int i = n / 2 + 1; i <= n; i++) {
res += dp[n - 1][i];
}
cout << res;
}
| #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define pb push_back
#define ins insert
#define pob pop_back
#define er erase
#define emp empty
#define f first
#define s second
#define ff f.f
#define fs f.s
#define sf s.f
#define ss s.s
#define var auto
using namespace std;
template <typename T> using s = set<T>;
template <typename T> using v = vector<T>;
template <typename T1, typename T2> using p = pair<T1, T2>;
typedef long long ll;
typedef p<int, int> pii;
typedef v<int> vi;
typedef v<pii> vpii;
typedef s<int> si;
typedef s<pii> spii;
const int Max = 4e3 + 100;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
int n;
double dp[Max][Max];
double A[Max];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> A[i];
dp[0][0] = 1 - A[0];
dp[0][1] = A[0];
for (int i = 1; i < n; i++) {
for (int j = 0; j <= i + 1; j++) {
if (j > 0)
dp[i][j] = dp[i - 1][j - 1] * A[i] + dp[i - 1][j] * (1 - A[i]);
else
dp[i][j] = dp[i - 1][j] * (1 - A[i]);
}
}
double res = 0;
for (int i = n / 2 + 1; i <= n; i++) {
res += dp[n - 1][i];
}
cout << setprecision(10) << res;
}
| [
"io.output.change"
] | 977,239 | 977,240 | u979412452 | cpp |
p03168 | #include <iomanip>
#include <iostream>
using namespace std;
float dp[3005][3005];
int main() {
int n;
double p[3005], rez = 0.0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
dp[0][0] = 1;
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] * p[i];
dp[i][j] += dp[i - 1][j] * (1 - p[i]);
}
}
for (int i = 1; i <= n; i++) {
if (i > n - i)
rez += dp[n][i];
}
cout << fixed << setprecision(10) << rez;
} | #include <iomanip>
#include <iostream>
using namespace std;
double dp[3005][3005];
int main() {
int n;
double p[3005], rez = 0.0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
dp[0][0] = 1;
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] * p[i];
dp[i][j] += dp[i - 1][j] * (1 - p[i]);
}
}
for (int i = 1; i <= n; i++) {
if (i > n - i)
rez += dp[n][i];
}
cout << fixed << setprecision(10) << rez;
}
| [
"variable_declaration.type.primitive.change"
] | 977,243 | 977,242 | u756453937 | cpp |
p03168 | #include <iomanip>
#include <iostream>
using namespace std;
float dp[3005][3005];
int main() {
int n;
double p[3005], rez = 0.0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
dp[0][0] = 1;
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] * p[i];
dp[i][j] += dp[i - 1][j] * (1 - p[i]);
}
}
for (int i = 1; i <= n; i++) {
if (i > n - i)
rez += dp[n][i];
}
cout << fixed << setprecision(10) << rez;
} | #include <iomanip>
#include <iostream>
using namespace std;
double dp[3005][3005];
int main() {
int n;
double p[3005], rez = 0.0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
dp[0][0] = 1;
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] * p[i];
dp[i][j] += dp[i - 1][j] * (1 - p[i]);
}
}
for (int i = 1; i <= n; i++) {
if (i > n - i)
rez += dp[n][i];
}
cout << fixed << setprecision(12) << rez;
} | [
"variable_declaration.type.primitive.change",
"literal.number.change",
"io.output.change"
] | 977,243 | 977,245 | u756453937 | cpp |
p03168 | #include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll inf = 1e9 + 7;
const ll mod = 1e9 + 7;
int main() {
ll n;
cin >> n;
vector<vector<double>> dp(n + 1, vector<double>(n + 1));
dp[0][0] = 1.00;
rep(i, n) {
double p;
cin >> p;
rep(j, n) {
dp[i + 1][j] += dp[i][j] * (1.00 - p);
dp[i + 1][j + 1] += dp[i][j] * p;
}
}
double ans = 0.000;
rep(i, n + 1) {
if (i > n - i)
ans += dp[n][i];
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll inf = 1e9 + 7;
const ll mod = 1e9 + 7;
int main() {
ll n;
cin >> n;
vector<vector<double>> dp(n + 1, vector<double>(n + 1));
dp[0][0] = 1.00;
rep(i, n) {
double p;
cin >> p;
rep(j, n) {
dp[i + 1][j] += dp[i][j] * (1.00 - p);
dp[i + 1][j + 1] += dp[i][j] * p;
}
}
double ans = 0.000;
rep(i, n + 1) {
if (i > n - i)
ans += dp[n][i];
}
cout << setprecision(15) << ans << endl;
} | [
"io.output.change"
] | 977,250 | 977,251 | u339937125 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T> void view(const std::vector<T> &v) {
for (const auto &e : v) {
std::cout << e << " ";
}
std::cout << std::endl;
}
template <typename T> void view(const std::vector<std::vector<T>> &vv) {
for (const auto &v : vv) {
view(v);
}
}
#pragma endregion
#pragma region chminmax
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#pragma endregion
int main() {
int n;
cin >> n;
int half = n + 1 / 2;
vector<double> p(n);
rep(i, n) cin >> p[i];
vector<vector<double>> dp(n + 1, vector<double>(n + 1));
dp[0][0] = 1.;
rep(i, n) {
rep(j, i + 1) {
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 k = half - 1; k <= n; k++) {
res += dp[n][k];
}
cout << fixed << setprecision(10) << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T> void view(const std::vector<T> &v) {
for (const auto &e : v) {
std::cout << e << " ";
}
std::cout << std::endl;
}
template <typename T> void view(const std::vector<std::vector<T>> &vv) {
for (const auto &v : vv) {
view(v);
}
}
#pragma endregion
#pragma region chminmax
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#pragma endregion
int main() {
int n;
cin >> n;
int half = (n + 1) / 2;
vector<double> p(n);
rep(i, n) cin >> p[i];
vector<vector<double>> dp(n + 1, vector<double>(n + 1));
dp[0][0] = 1.;
rep(i, n) {
rep(j, i + 1) {
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 k = half; k <= n; k++) {
res += dp[n][k];
}
cout << fixed << setprecision(10) << res << endl;
return 0;
} | [
"control_flow.loop.for.initializer.change",
"expression.operation.binary.remove"
] | 977,256 | 977,257 | u395620499 | cpp |
p03168 | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int>> mati;
typedef vector<vector<double>> matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define rep(i, x, y) for (int i = (x); i < (y); ++i)
template <typename T> void vec_print(vector<T> VEC) {
rep(i, 0, VEC.size()) { cout << VEC[i] << " "; }
cout << "\n";
};
template <typename T>
void mat_print(vector<vector<T>> MAT){
rep(i, 0, MAT.size()){rep(j, 0, MAT[i].size()){cout << MAT[i][j] << " ";
}
cout << "\n";
}
}
;
template <typename CLASS1, typename CLASS2> class HOGE {
public:
CLASS1 key;
CLASS2 value;
HOGE(ll key, ll value) {
this->key = index;
this->value = value;
};
~HOGE(void) { return; };
void print(void) {
cout << "key : " << key << ", value : " << value << "\n";
return;
};
bool operator==(const HOGE &obj) { return (this->value == obj.value); };
bool operator<(const HOGE &obj) { return (this->value < obj.value); };
bool operator>(const HOGE &obj) { return (this->value > obj.value); };
};
constexpr int INF = (1 << 30);
constexpr ll INFLL = 1LL << 62;
constexpr long double EPS = 1e-12;
void calc_dp(const int start, const vector<double> &p, vector<double> &dp) {
if (start == p.size() - 1) {
dp[0] = 1.0 - p[start];
dp[1] = p[start];
return;
}
calc_dp(start + 1, p, dp);
dp[p.size() - start] = dp[p.size() - start - 1] * p[start];
for (int i = p.size() - start - 1; i > 0; --i) {
dp[i] = dp[i] * (1.0 - p[start]) + dp[i - 1] * p[start];
}
dp[0] = dp[0] * (1.0 - p[start]);
return;
}
int main() {
cin.tie(0); // cut the cin and cout (default, std::flush is performed after
// std::cin)
ios::sync_with_stdio(
false); // cut the iostream and stdio (DON'T endl; BUT "\n";)
ll N;
cin >> N;
// ans 1
/*
vector<double> p(N);
rep(i, 0, N){
cin >> p[i];
}
vector<double> dp(N+1, 0.0);
calc_dp(0, p, dp);
*/
// ans 2
vector<double> dp(N / 2 + 1, 0.0);
double tmp;
cin >> tmp;
dp[0] = tmp;
dp[1] = 1.0 - tmp;
rep(i, 1, N / 2 + 1) {
cin >> tmp;
dp[i + 1] = dp[i] * (1.0 - tmp);
for (int j = i; j > 0; --j) {
dp[j] = dp[j] * tmp + dp[j - 1] * (1.0 - tmp);
}
dp[0] = dp[0] * tmp;
}
rep(i, N / 2 + 1, N) {
cin >> tmp;
for (int j = N / 2; j > 0; --j) {
dp[j] = dp[j] * tmp + dp[j - 1] * (1.0 - tmp);
}
dp[0] = dp[0] * tmp;
}
double ans = 0.0;
rep(i, 0, N / 2 + 1) { ans += dp[i]; }
printf("%.10lf\n", ans);
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int>> mati;
typedef vector<vector<double>> matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define rep(i, x, y) for (int i = (x); i < (y); ++i)
template <typename T> void vec_print(vector<T> VEC) {
rep(i, 0, VEC.size()) { cout << VEC[i] << " "; }
cout << "\n";
};
template <typename T>
void mat_print(vector<vector<T>> MAT){
rep(i, 0, MAT.size()){rep(j, 0, MAT[i].size()){cout << MAT[i][j] << " ";
}
cout << "\n";
}
}
;
template <typename CLASS1, typename CLASS2> class HOGE {
public:
CLASS1 key;
CLASS2 value;
HOGE(ll key, ll value) {
this->key = index;
this->value = value;
};
~HOGE(void) { return; };
void print(void) {
cout << "key : " << key << ", value : " << value << "\n";
return;
};
bool operator==(const HOGE &obj) { return (this->value == obj.value); };
bool operator<(const HOGE &obj) { return (this->value < obj.value); };
bool operator>(const HOGE &obj) { return (this->value > obj.value); };
};
constexpr int INF = (1 << 30);
constexpr ll INFLL = 1LL << 62;
constexpr long double EPS = 1e-12;
void calc_dp(const int start, const vector<double> &p, vector<double> &dp) {
if (start == p.size() - 1) {
dp[0] = 1.0 - p[start];
dp[1] = p[start];
return;
}
calc_dp(start + 1, p, dp);
dp[p.size() - start] = dp[p.size() - start - 1] * p[start];
for (int i = p.size() - start - 1; i > 0; --i) {
dp[i] = dp[i] * (1.0 - p[start]) + dp[i - 1] * p[start];
}
dp[0] = dp[0] * (1.0 - p[start]);
return;
}
int main() {
cin.tie(0); // cut the cin and cout (default, std::flush is performed after
// std::cin)
ios::sync_with_stdio(
false); // cut the iostream and stdio (DON'T endl; BUT "\n";)
ll N;
cin >> N;
// ans 1
/*
vector<double> p(N);
rep(i, 0, N){
cin >> p[i];
}
vector<double> dp(N+1, 0.0);
calc_dp(0, p, dp);
*/
// ans 2
vector<double> dp(N / 2 + 2, 0.0);
double tmp;
cin >> tmp;
dp[0] = tmp;
dp[1] = 1.0 - tmp;
rep(i, 1, N / 2 + 1) {
cin >> tmp;
dp[i + 1] = dp[i] * (1.0 - tmp);
for (int j = i; j > 0; --j) {
dp[j] = dp[j] * tmp + dp[j - 1] * (1.0 - tmp);
}
dp[0] = dp[0] * tmp;
}
rep(i, N / 2 + 1, N) {
cin >> tmp;
for (int j = N / 2; j > 0; --j) {
dp[j] = dp[j] * tmp + dp[j - 1] * (1.0 - tmp);
}
dp[0] = dp[0] * tmp;
}
double ans = 0.0;
rep(i, 0, N / 2 + 1) { ans += dp[i]; }
printf("%.10lf\n", ans);
return 0;
} | [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 977,258 | 977,259 | u355335354 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
double dp[3000][3000];
int n;
double arr[3000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[i][0] = (1.00 - arr[i]) * dp[i - 1][0];
dp[0][i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = dp[i - 1][j] * (1.00 - arr[i]) + dp[i - 1][j - 1] * arr[i];
}
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << ans << setprecision(9);
} | #include <bits/stdc++.h>
using namespace std;
double dp[3000][3000];
int n;
double arr[3000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[i][0] = (1.00 - arr[i]) * dp[i - 1][0];
dp[0][i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = dp[i - 1][j] * (1.00 - arr[i]) + dp[i - 1][j - 1] * arr[i];
}
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << fixed << setprecision(11) << ans;
} | [
"identifier.change",
"io.output.change",
"literal.number.change"
] | 977,260 | 977,261 | u064458730 | cpp |
p03168 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll MOD = (1e9 + 7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll factorial(ll n, ll m = 2) {
// calculate n!
m = max(2LL, m);
ll rtn = 1;
for (ll i = m; i <= n; i++) {
rtn = (rtn * i) % MOD;
}
return rtn;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
ll modpow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<double> p(n);
rep(i, n) cin >> p[i];
vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
dp[0][0] = 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 ans = 0;
for (int i = n / 2 + 1; i <= n; ++i) {
ans += dp[n][i];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll MOD = (1e9 + 7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll factorial(ll n, ll m = 2) {
// calculate n!
m = max(2LL, m);
ll rtn = 1;
for (ll i = m; i <= n; i++) {
rtn = (rtn * i) % MOD;
}
return rtn;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
ll modpow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<double> p(n);
rep(i, n) cin >> p[i];
vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
dp[0][0] = 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 ans = 0;
for (int i = n / 2 + 1; i <= n; ++i) {
ans += dp[n][i];
}
cout << setprecision(10) << ans << endl;
return 0;
} | [
"io.output.change"
] | 977,266 | 977,267 | u963903527 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
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;
}
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
const ll INF = 1ll << 60;
vvec<int> node(100100, vec<int>());
vec<int> dp(100100, -1);
int main() {
int n;
cin >> n;
vvec<double> dp(3000, vec<double>(3000));
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
double p;
cin >> p;
for (int j = 0; j <= n; j++) {
if (j == 0)
dp[i][j] = dp[i - 1][j] * (1 - p);
else
dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j] * (1 - p);
}
// cout << 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;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
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;
}
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
const ll INF = 1ll << 60;
vvec<int> node(100100, vec<int>());
vec<int> dp(100100, -1);
int main() {
int n;
cin >> n;
vvec<double> dp(3000, vec<double>(3000));
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
double p;
cin >> p;
for (int j = 0; j <= n; j++) {
if (j == 0)
dp[i][j] = dp[i - 1][j] * (1 - p);
else
dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j] * (1 - p);
}
// cout << 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;
} | [
"io.output.change"
] | 977,272 | 977,273 | u611777990 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) {
return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
return b < a && (a = b, true);
}
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a, x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define INF 2e9
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<double> p(n + 1);
rep(i, n) { cin >> p[i]; }
vector<vector<double>> dp(n + 1, vector<double>(n + 1));
dp[0][0] = 1;
double ans = 0;
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]);
}
}
for (int i = n; i > n / 2; i--) {
ans += dp[n][i];
}
cout << ans << '\n';
return (0);
}
| #include <bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) {
return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
return b < a && (a = b, true);
}
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a, x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for (int i = x; i < n; i++)
#define INF 2e9
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<double> p(n + 1);
rep(i, n) { cin >> p[i]; }
vector<vector<double>> dp(n + 1, vector<double>(n + 1));
dp[0][0] = 1;
double ans = 0;
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]);
}
}
for (int i = n; i > n / 2; i--) {
ans += dp[n][i];
}
cout << setprecision(10) << ans << '\n';
return (0);
}
| [
"io.output.change"
] | 977,278 | 977,277 | u132033278 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1e9 + 7
#define pll pair<long long, long long>
#define pdd pair<long double, long double>
#define vll vector<ll>
#define rep(i, j, n) for (int i = j; i < n; i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
priority_queue<pll, vector<pll>, greater<pll>> pq;
priority_queue<ll, vector<ll>, greater<ll>> pq1;
ll n;
vector<double> arr(3000);
vector<vector<double>> dp(3000, vector<double>(3000, -1));
double solve(ll i, ll j) {
if (i == 0 && j == 0)
return 1 - arr[0];
if (i == 0 && j == 1)
return arr[0];
if (i == 0)
return 0;
if (j < 0)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
dp[i][j] = arr[i] * solve(i - 1, j - 1) + (1 - arr[i]) * solve(i - 1, j);
return dp[i][j];
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
if (n == 1) {
cout << arr[0];
return 0;
}
dp[0][0] = 1;
double ans = 0;
for (ll i = n / 2 + 1; i <= n; i++) {
ans = ans + solve(n - 1, i);
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1e9 + 7
#define pll pair<long long, long long>
#define pdd pair<long double, long double>
#define vll vector<ll>
#define rep(i, j, n) for (int i = j; i < n; i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
priority_queue<pll, vector<pll>, greater<pll>> pq;
priority_queue<ll, vector<ll>, greater<ll>> pq1;
ll n;
vector<double> arr(3000);
vector<vector<double>> dp(3000, vector<double>(3000, -1));
double solve(ll i, ll j) {
if (i == 0 && j == 0)
return 1 - arr[0];
if (i == 0 && j == 1)
return arr[0];
if (i == 0)
return 0;
if (j < 0)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
dp[i][j] = arr[i] * solve(i - 1, j - 1) + (1 - arr[i]) * solve(i - 1, j);
return dp[i][j];
}
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
if (n == 1) {
cout << arr[0];
return 0;
}
dp[0][0] = 1;
double ans = 0;
for (ll i = n / 2 + 1; i <= n; i++) {
ans = ans + solve(n - 1, i);
}
cout << setprecision(27) << ans;
return 0;
}
| [
"io.output.change"
] | 977,279 | 977,280 | u029479695 | cpp |
p03168 | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(j, n) for (int j = 0; j < (n); ++j)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define srep2(j, s, t) for (int j = s; j < t; ++j)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T> string join(const v(T) & v) {
stringstream s;
rep(i, sz(v)) s << ' ' << v[i];
return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
if (sz(v))
o << join(v);
return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
return o << v.fi << "," << v.se;
}
template <typename T> inline ll suma(const v(T) & a) {
ll res(0);
for (auto &&x : a)
res += x;
return res;
}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("YES"); } \
else { \
puts("NO"); \
}
const int MX = 200005;
int N;
double p[3010];
double memo[3010][3010];
double dfs(int uranum, int nowcoin) {
if (nowcoin > -1 && memo[uranum][nowcoin] > -0.99) {
return memo[uranum][nowcoin];
} else {
if (nowcoin == N - 1) {
memo[uranum][nowcoin] = 1.0;
return 1.0;
}
if (uranum >= (N - 1) / 2) {
double omote = p[nowcoin + 1] * dfs(uranum, nowcoin + 1);
memo[uranum][nowcoin] = omote;
return omote;
} else {
double omote = p[nowcoin + 1] * dfs(uranum, nowcoin + 1);
double ura = (1.0 - p[nowcoin + 1]) * dfs(uranum + 1, nowcoin + 1);
memo[uranum][nowcoin] = ura + omote;
return ura + omote;
}
}
}
int main() {
cin >> N;
rep(i, N) {
rep2(j, N) { memo[i][j] = -1.0; }
}
rep(i, N) { cin >> p[i]; }
double ans = dfs(0, -1);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(j, n) for (int j = 0; j < (n); ++j)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define srep2(j, s, t) for (int j = s; j < t; ++j)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T> string join(const v(T) & v) {
stringstream s;
rep(i, sz(v)) s << ' ' << v[i];
return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
if (sz(v))
o << join(v);
return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
return o << v.fi << "," << v.se;
}
template <typename T> inline ll suma(const v(T) & a) {
ll res(0);
for (auto &&x : a)
res += x;
return res;
}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("YES"); } \
else { \
puts("NO"); \
}
const int MX = 200005;
int N;
double p[3010];
double memo[3010][3010];
double dfs(int uranum, int nowcoin) {
if (nowcoin > -1 && memo[uranum][nowcoin] > -0.99) {
return memo[uranum][nowcoin];
} else {
if (nowcoin == N - 1) {
memo[uranum][nowcoin] = 1.0;
return 1.0;
}
if (uranum >= (N - 1) / 2) {
double omote = p[nowcoin + 1] * dfs(uranum, nowcoin + 1);
memo[uranum][nowcoin] = omote;
return omote;
} else {
double omote = p[nowcoin + 1] * dfs(uranum, nowcoin + 1);
double ura = (1.0 - p[nowcoin + 1]) * dfs(uranum + 1, nowcoin + 1);
memo[uranum][nowcoin] = ura + omote;
return ura + omote;
}
}
}
int main() {
cin >> N;
rep(i, N) {
rep2(j, N) { memo[i][j] = -1.0; }
}
rep(i, N) { cin >> p[i]; }
double ans = dfs(0, -1);
cout << setprecision(10) << ans << endl;
return 0;
} | [
"io.output.change"
] | 977,286 | 977,287 | u340293807 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define INF (int)1e9
#define pb push_back
#define fastIO \
ios::sync_with_stdio(0); \
cin.tie(0);
int n;
double cache[3005][3005];
bool visited[3005][3005];
vector<double> prob;
double dpSol(int i, int j) {
int mid = (n / 2);
if (i == n) {
if (j > mid)
return 1;
return 0;
}
double &res = cache[i][j];
if (visited[i][j])
return res;
visited[i][j] = 1;
return res =
dpSol(i + 1, j) * (1.0 - prob[i]) + dpSol(i + 1, j + 1) * prob[i];
}
int main() {
fastIO
cin >>
n;
prob = vector<double>(n);
for (int i = 0; i < n; ++i)
cin >> prob[i];
for (int i = 0; i < 3005; ++i)
for (int j = 0; j < 3005; ++j)
visited[i][j] = 0;
cout << dpSol(0, 0);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define INF (int)1e9
#define pb push_back
#define fastIO \
ios::sync_with_stdio(0); \
cin.tie(0);
int n;
double cache[3005][3005];
bool visited[3005][3005];
vector<double> prob;
double dpSol(int i, int j) {
int mid = (n / 2);
if (i == n) {
if (j > mid)
return 1;
return 0;
}
double &res = cache[i][j];
if (visited[i][j])
return res;
visited[i][j] = 1;
return res =
dpSol(i + 1, j) * (1.0 - prob[i]) + dpSol(i + 1, j + 1) * prob[i];
}
int main() {
fastIO
cin >>
n;
prob = vector<double>(n);
for (int i = 0; i < n; ++i)
cin >> prob[i];
for (int i = 0; i < 3005; ++i)
for (int j = 0; j < 3005; ++j)
visited[i][j] = 0;
cout << setprecision(10) << dpSol(0, 0);
return 0;
} | [
"io.output.change"
] | 977,288 | 977,289 | u254167435 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)
#define fast \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false)
#define filename "lynext"
#define freop \
freopen(filename ".cik", "w", stdout); \
freopen(filename ".gir", "r", stdin)
const long long int N = ((long long int)3e3) + 5;
const long long int M = ((long long int)1e3) + 5;
const long long int llinf = (long long int)1e18;
const int inf = INT_MAX;
typedef long long int lli;
int n;
double arr[N];
double dp[N][N];
double f(int x, int head, int tail) {
if (dp[x][head] != -1.0f)
return dp[x][head];
if (x > n) {
if (head > tail)
return 1.0f;
return 0.0f;
}
double t1 = f(x + 1, head + 1, tail) * arr[x];
double t2 = f(x + 1, head, tail + 1) * (1.0f - arr[x]);
return dp[x][head] = t1 + t2;
}
int main() {
fast;
// freop;
cin >> n;
for (int i = 1; i <= N - 1; i++)
for (int j = 1; j <= N - 1; j++)
dp[i][j] = -1.0f;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
cout << std::setprecision(10) << f(1, 0, 0) << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)
#define fast \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false)
#define filename "lynext"
#define freop \
freopen(filename ".cik", "w", stdout); \
freopen(filename ".gir", "r", stdin)
const long long int N = ((long long int)3e3) + 5;
const long long int M = ((long long int)1e3) + 5;
const long long int llinf = (long long int)1e18;
const int inf = INT_MAX;
typedef long long int lli;
int n;
double arr[N];
double dp[N][N];
double f(int x, int head, int tail) {
if (dp[x][head] != -1.0f)
return dp[x][head];
if (x > n) {
if (head > tail)
return 1.0f;
return 0.0f;
}
double t1 = f(x + 1, head + 1, tail) * arr[x];
double t2 = f(x + 1, head, tail + 1) * (1.0f - arr[x]);
return dp[x][head] = t1 + t2;
}
int main() {
fast;
// freop;
cin >> n;
for (int i = 0; i <= N - 1; i++)
for (int j = 0; j <= N - 1; j++)
dp[i][j] = -1.0f;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
cout << std::setprecision(10) << f(1, 0, 0) << "\n";
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 977,294 | 977,295 | u997979021 | cpp |
p03168 | /*
Author: Racer5x
*************************************** UNAUTHORISED COPYING OF CODE
PROHIBITED **********************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pb emplace_back
#define pf emplace_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 998244353
#define PI 3.141592653589
#define tezz \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define MAX 2000000000000000000
#define M 1000000007
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x, int n) {
int result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result % M;
}
double dp[3005][3005] = {0.0};
signed main() {
tezz
memset(dp, 0.0, sizeof(dp));
int n;
cin >> n;
vector<double> v(n);
for (double &x : v)
cin >> x;
dp[0][0] = 1 - v[0];
dp[0][1] = v[0];
for (int i = 1; i < n; i++) {
dp[i][0] = dp[i - 1][0] * (1 - v[i]);
}
for (int i = 1; i < n; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = v[i] * dp[i - 1][j - 1] + (1 - v[i]) * dp[i - 1][j];
}
}
/*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 i = n; i > n / 2; i--) {
ans += dp[n - 1][i];
} // cout<<dp[n-1][i]<<" ";}
cout << ans;
} | /*
Author: Racer5x
*************************************** UNAUTHORISED COPYING OF CODE
PROHIBITED **********************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pb emplace_back
#define pf emplace_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 998244353
#define PI 3.141592653589
#define tezz \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define MAX 2000000000000000000
#define M 1000000007
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x, int n) {
int result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result % M;
}
double dp[3005][3005] = {0.0};
signed main() {
tezz
memset(dp, 0.0, sizeof(dp));
int n;
cin >> n;
vector<double> v(n);
for (double &x : v)
cin >> x;
dp[0][0] = 1 - v[0];
dp[0][1] = v[0];
for (int i = 1; i < n; i++) {
dp[i][0] = dp[i - 1][0] * (1 - v[i]);
}
for (int i = 1; i < n; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = v[i] * dp[i - 1][j - 1] + (1 - v[i]) * dp[i - 1][j];
}
}
/*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 i = n; i > n / 2; i--) {
ans += dp[n - 1][i];
} // cout<<dp[n-1][i]<<" ";}
cout << setprecision(15) << ans;
}
| [
"io.output.change"
] | 977,302 | 977,303 | u488763956 | cpp |
p03168 | /*
Author: Racer5x
*************************************** UNAUTHORISED COPYING OF CODE
PROHIBITED **********************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pb emplace_back
#define pf emplace_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 998244353
#define PI 3.141592653589
#define tezz \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define MAX 2000000000000000000
#define M 1000000007
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x, int n) {
int result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result % M;
}
double dp[3005][3005] = {0.0};
signed main() {
tezz
// memset(dp,0,sizeof(dp));
for (int i = 0; i < 3005; i++) {
for (int j = 0; j < 3005; j++) {
dp[i][j] = 0;
}
}
int n;
cin >> n;
vector<double> v(n);
for (double &x : v)
cin >> x;
dp[0][0] = 1.0 - v[0];
dp[0][1] = v[0];
for (int i = 1; i < n; i++) {
dp[i][0] = dp[i - 1][0] * (1 - v[i]);
}
for (int i = 1; i < n; i++) {
for (int j = 1; j <= i + 1; j++) {
dp[i][j] = v[i] * dp[i - 1][j - 1] + (1 - v[i]) * dp[i - 1][j];
}
}
/*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 i = 0; i < n + 1; i++) {
if (i > n - i)
ans += dp[n - 1][i];
} // cout<<dp[n-1][i]<<" ";}
cout << ans;
}
| /*
Author: Racer5x
*************************************** UNAUTHORISED COPYING OF CODE
PROHIBITED **********************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pb emplace_back
#define pf emplace_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 998244353
#define PI 3.141592653589
#define tezz \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define MAX 2000000000000000000
#define M 1000000007
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x, int n) {
int result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result % M;
}
double dp[3005][3005] = {0.0};
signed main() {
tezz
// memset(dp,0,sizeof(dp));
for (int i = 0; i < 3005; i++) {
for (int j = 0; j < 3005; j++) {
dp[i][j] = 0;
}
}
int n;
cin >> n;
vector<double> v(n);
for (double &x : v)
cin >> x;
dp[0][0] = 1.0 - v[0];
dp[0][1] = v[0];
for (int i = 1; i < n; i++) {
dp[i][0] = dp[i - 1][0] * (1 - v[i]);
}
for (int i = 1; i < n; i++) {
for (int j = 1; j <= i + 1; j++) {
dp[i][j] = v[i] * dp[i - 1][j - 1] + (1 - v[i]) * dp[i - 1][j];
}
}
/*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 i = 0; i < n + 1; i++) {
if (i > n - i)
ans += dp[n - 1][i];
} // cout<<dp[n-1][i]<<" ";}
cout << setprecision(15) << ans;
}
| [
"io.output.change"
] | 977,304 | 977,305 | u488763956 | cpp |
p03168 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
bool visited[3000][3000];
double dp[3000][3000];
double solve(int h, int t, double *p) {
if (visited[h][t] == true)
return dp[h][t];
else {
if (h > t) {
dp[h][t] = 0;
visited[h][t] = true;
return 0;
}
else if (h == t && t == 1) {
dp[h][t] = p[t - 1];
visited[h][t] = true;
return dp[h][t];
}
else if (h == 0 && t == 1) {
dp[h][t] = 1 - p[t - 1];
visited[h][t] = true;
return dp[h][t];
}
else {
dp[h][t] = (h == 0) ? 0
: (p[t - 1] * solve(h - 1, t - 1, p)) +
(1 - p[t - 1]) * solve(h, t - 1, p);
visited[h][t] = true;
return dp[h][t];
}
}
}
int main() {
cin >> n;
double p[n];
for (int i = 0; i < n; i++)
cin >> p[i];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
visited[i][j] = false;
double pro = 0;
for (int i = n / 2 + 1; i <= n; i++) {
pro += solve(i, n, p);
}
cout.precision(9);
cout << fixed << pro << endl;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
bool visited[3000][3000];
double dp[3000][3000];
double solve(int h, int t, double *p) {
if (visited[h][t] == true)
return dp[h][t];
else {
if (h > t) {
dp[h][t] = 0;
visited[h][t] = true;
return 0;
}
else if (h == t && t == 1) {
dp[h][t] = p[t - 1];
visited[h][t] = true;
return dp[h][t];
}
else if (h == 0 && t == 1) {
dp[h][t] = 1 - p[t - 1];
visited[h][t] = true;
return dp[h][t];
}
else {
dp[h][t] = ((h == 0) ? 0 : (p[t - 1] * solve(h - 1, t - 1, p))) +
(1 - p[t - 1]) * solve(h, t - 1, p);
visited[h][t] = true;
return dp[h][t];
}
}
}
int main() {
cin >> n;
double p[n];
for (int i = 0; i < n; i++)
cin >> p[i];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
visited[i][j] = false;
double pro = 0;
for (int i = n / 2 + 1; i <= n; i++) {
pro += solve(i, n, p);
}
cout.precision(9);
cout << fixed << pro << endl;
}
| [] | 977,310 | 977,311 | u791283132 | cpp |
p03168 |
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pd pair<double, double>
#define ld long double
#define pld pair<ld, ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005
using namespace std;
const int maxn = 2999 + 100;
double dp[maxn];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
#ifdef LOCAL_DEFINE
ifstream cin("input.txt");
#endif
int N;
cin >> N;
double p;
cin >> p;
dp[1] = p;
dp[0] = 1 - p;
for (int i = 2; i <= N; i++) {
cin >> p;
for (int j = i; j >= 0; j--)
dp[j] = (j > 0 ? dp[j - 1] * p : 0) + dp[j] * (1 - p);
}
double ans = 0;
for (int i = N; i > N - i; i--)
ans += dp[i];
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pd pair<double, double>
#define ld long double
#define pld pair<ld, ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005
using namespace std;
const int maxn = 2999 + 100;
double dp[maxn];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
#ifdef LOCAL_DEFINE
ifstream cin("input.txt");
#endif
int N;
cin >> N;
double p;
cin >> p;
dp[1] = p;
dp[0] = 1 - p;
for (int i = 2; i <= N; i++) {
cin >> p;
for (int j = i; j >= 0; j--)
dp[j] = (j > 0 ? dp[j - 1] * p : 0) + dp[j] * (1 - p);
}
double ans = 0;
for (int i = N; i > N - i; i--)
ans += dp[i];
cout << setprecision(12) << ans << '\n';
}
| [
"io.output.change"
] | 977,312 | 977,313 | u663257960 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
double dp[3005];
int main() {
int n;
cin >> n;
double p;
dp[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> p;
for (int j = i; j >= 0; j--) {
dp[j] = (j == 0 ? 0 : dp[j - 1] * p) + dp[j] * (1 - p);
}
}
// dp[j]: j tane tura gelme olasılığı
double ans = 0;
for (int i = 0; i <= n; i++) {
if (i > n - i) {
ans += dp[i];
}
}
printf("%.10llf\n", ans);
}
| #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
double dp[3005];
int main() {
int n;
cin >> n;
double p;
dp[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> p;
for (int j = i; j >= 0; j--) {
dp[j] = (j == 0 ? 0 : dp[j - 1] * p) + dp[j] * (1 - p);
}
}
// dp[j]: j tane tura gelme olasılığı
double ans = 0;
for (int i = 0; i <= n; i++) {
if (i > n - i) {
ans += dp[i];
}
}
printf("%.10lf\n", ans);
}
| [
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 977,318 | 977,319 | u923368296 | cpp |
p03168 | #ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
#define y0 qvya13579
#define y1 qvyb24680
#define j0 qvja13579
#define j1 qvjb24680
#define next qvne13579xt
#define prev qvpr13579ev
#define INF 1000000007
#define MOD 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS \
cin.tie(0); \
ios::sync_with_stdio(false)
#define M_P make_pair
#define PU_B push_back
#define PU_F push_front
#define PO_B pop_back
#define PO_F pop_front
#define U_B upper_bound
#define L_B lower_bound
#define B_S binary_search
#define PR_Q priority_queue
#define FIR first
#define SEC second
#if __cplusplus < 201103L
#define stoi(argument_string) atoi((argument_string).c_str())
#define stoll(argument_string) atoll((argument_string).c_str())
#endif
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP_R(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define FOR(i, m, n) for (int i = ((int)(m)); i < (int)(n); ++i)
#define FOR_R(i, m, n) for (int i = ((int)(m)-1); i >= (int)(n); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SIZ(x) ((int)(x).size())
#define CIN(x) cin >> (x)
#define CIN2(x, y) cin >> (x) >> (y)
#define CIN3(x, y, z) cin >> (x) >> (y) >> (z)
#define CIN4(x, y, z, w) cin >> (x) >> (y) >> (z) >> (w)
#define CIN5(x, y, z, w, u) cin >> (x) >> (y) >> (z) >> (w) >> (u)
#define SCAND(x) scanf("%d", &(x))
#define SCAND2(x, y) scanf("%d%d", &(x), &(y))
#define SCAND3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z))
#define SCAND4(x, y, z, w) scanf("%d%d%d%d", &(x), &(y), &(z), &(w))
#define SCAND5(x, y, z, w, u) scanf("%d%d%d%d%d", &(x), &(y), &(z), &(w), &(u))
#define SCANLLD(x) scanf("%lld", &(x))
#define SCANLLD2(x, y) scanf("%lld%lld", &(x), &(y))
#define SCANLLD3(x, y, z) scanf("%lld%lld%lld", &(x), &(y), &(z))
#define SCANLLD4(x, y, z, w) scanf("%lld%lld%lld%lld", &(x), &(y), &(z), &(w))
#define SCANLLD5(x, y, z, w, u) \
scanf("%lld%lld%lld%lld%lld", &(x), &(y), &(z), &(w), &(u))
#define I64DSCAN(x) scanf("%I64d", &(x))
#define I64DSCAN2(x, y) scanf("%I64d%I64d", &(x), &(y))
#define I64DSCAN3(x, y, z) scanf("%I64d%I64d%I64d", &(x), &(y), &(z))
#define I64DSCAN4(x, y, z, w) \
scanf("%I64d%I64d%I64d%I64d", &(x), &(y), &(z), &(w))
#define I64DSCAN5(x, y, z, w, u) \
scanf("%I64d%I64d%I64d%I64d%I64d", &(x), &(y), &(z), &(w), &(u))
#define PRINTD(x) printf("%d\n", (x))
#define PRINTLLD(x) printf("%lld\n", (x))
#define PRINTI64D(x) printf("%I64d\n", (x))
#define DEBUG(argument) cerr << (#argument) << " : " << (argument) << "\n"
typedef long long int lli;
using namespace std;
bool compare_by_2nd(pair<int, int> a, pair<int, int> b) {
if (a.second != b.second) {
return a.second < b.second;
} else {
return a.first < b.first;
}
}
int ctoi(char c) {
if (c >= '0' and c <= '9') {
return (int)(c - '0');
}
return -1;
}
int alphabet_pos(char c) {
if (c >= 'a' and c <= 'z') {
return (int)(c - 'a');
}
return -1;
}
int alphabet_pos_capital(char c) {
if (c >= 'A' and c <= 'Z') {
return (int)(c - 'A');
}
return -1;
}
vector<string> split(string str, char ch) {
int first = 0;
int last = str.find_first_of(ch);
if (last == string::npos) {
last = SIZ(str);
}
vector<string> result;
while (first < SIZ(str)) {
string Ssubstr(str, first, last - first);
result.push_back(Ssubstr);
first = last + 1;
last = str.find_first_of(ch, first);
if (last == string::npos) {
last = SIZ(str);
}
}
return result;
}
int gcd(int a, int b) // assuming a,b >= 1
{
if (a < b) {
swap(a, b);
}
if (a == 0) {
return b;
}
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
long long gcd(long long a, long long b) // assuming a,b >= 1
{
if (a < b) {
swap(a, b);
}
if (a == 0LL) {
return b;
}
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
return a * b / gcd(a, b);
}
long long lcm(long long a, long long b) // assuming a,b >= 1
{
return a * b / gcd(a, b);
}
long long pow_fast(long long x, long long n_power, long long modulus) {
if (n_power == 0) {
return 1;
}
if (n_power % 2 == 0) {
return pow_fast(x * x % modulus, n_power / 2, modulus);
}
return x * pow_fast(x, n_power - 1, modulus) % modulus;
}
struct CombinationTable {
vector<vector<long long>> val;
CombinationTable(int size)
: val(size + 1, vector<long long>(size + 1)) // constructor
{
for (int i = 0; i <= size; ++i) // note that 0 <= i <= size
{
for (int j = 0; j <= i; ++j) {
if (j == 0 or j == i) {
val[i][j] = 1LL;
} else {
val[i][j] = val[i - 1][j - 1] + val[i - 1][j];
}
}
}
}
};
void print_vector(vector<int> &h) {
int L = h.size();
for (int i = 0; i < L; ++i) {
printf("%d", h[i]);
if (i != L - 1) {
printf(" ");
} else {
printf("\n");
}
}
}
void print_vector(vector<long long> &h) {
int L = h.size();
for (int i = 0; i < L; ++i) {
printf("%lld", h[i]);
if (i != L - 1) {
printf(" ");
} else {
printf("\n");
}
}
}
void print_matrix2D(vector<vector<int>> &h) {
int Ly = h.size();
int Lx = h[0].size();
for (int i = 0; i < Ly; ++i) {
for (int j = 0; j < Lx; ++j) {
printf("%d", h[i][j]);
if (j != Lx - 1) {
printf(" ");
} else {
printf("\n");
}
}
}
}
void print_matrix2D(vector<vector<long long>> &h) {
int Ly = h.size();
int Lx = h[0].size();
for (int i = 0; i < Ly; ++i) {
for (int j = 0; j < Lx; ++j) {
printf("%lld", h[i][j]);
if (j != Lx - 1) {
printf(" ");
} else {
printf("\n");
}
}
}
}
void print_matrix2D(vector<string> &h) {
int Ly = h.size();
int Lx = h[0].size();
for (int i = 0; i < Ly; ++i) {
for (int j = 0; j < Lx; ++j) {
printf("%c", h[i][j]);
}
printf("\n");
}
}
void print_binary(int val, int num_digit = 31, bool verbose = false) {
for (int k = num_digit - 1; k >= 0; --k) {
if (verbose) {
printf("%d", (val >> k) & 1);
} else {
cerr << ((val >> k) & 1);
}
}
if (verbose) {
printf("\n");
} else {
cerr << "\n";
}
}
void print_binary(long long val, int num_digit = 63, bool verbose = false) {
for (int k = num_digit - 1; k >= 0; --k) {
if (verbose) {
printf("%lld", ((val >> k) & 1));
} else {
cerr << ((val >> k) & 1);
}
}
if (verbose) {
printf("\n");
} else {
cerr << "\n";
}
}
struct UnionFind // size-based
{
vector<int> parent, treesize;
UnionFind(int size)
: parent(size), treesize(size, 1) // constructor
{
for (int i = 0; i < size; ++i) {
parent[i] = i;
}
}
int root(int x) {
if (parent[x] == x) {
return x;
}
return parent[x] = root(parent[x]);
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y) {
return;
}
if (treesize[x] < treesize[y]) {
parent[x] = y;
treesize[y] += treesize[x];
} else {
parent[y] = x;
treesize[x] += treesize[y];
}
}
bool sametree(int x, int y) { return root(x) == root(y); }
int gettreesize(int x) { return treesize[root(x)]; }
};
template <typename Type_value>
struct SegmentTree // Range Minimum Query (RMQ)
{
private:
int n;
vector<Type_value> node;
Type_value identity_element_segmenttree;
public:
SegmentTree(vector<Type_value> v,
Type_value identity_element_st) // constructor
{
int sz = v.size();
identity_element_segmenttree = identity_element_st;
n = 1;
while (n < sz) {
n <<= 1;
}
node.resize(2 * n - 1, identity_element_segmenttree);
for (int i = 0; i < sz; ++i) {
node[i + n - 1] = v[i];
}
for (int i = n - 2; i >= 0; --i) {
node[i] = min(node[2 * i + 1], node[2 * i + 2]);
}
}
void update(int x, Type_value val) {
x += (n - 1);
node[x] = val;
while (x > 0) {
x = (x - 1) / 2;
node[x] = min(node[2 * x + 1], node[2 * x + 2]);
}
}
Type_value getmin(int a, int b, int k = 0, int l = 0,
int r = -1) // getting minimum value in [a,b)
{
// k : index of the referred node
// [l,r) : range covered by the k-th node
if (r < 0) {
r = n;
}
if (r <= a or b <= l) {
return identity_element_segmenttree;
}
if (a <= l and r <= b) {
return node[k];
}
Type_value vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
Type_value vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
};
template <typename Type_value>
struct BinaryIndexedTree // Range Sum Query (RSQ), 0-indexed
{
private:
int size_;
vector<Type_value> data;
public:
BinaryIndexedTree(int sz, Type_value identity_element_binaryindexedtree =
0.0) // constructor
{
size_ = sz;
data.resize(sz + 1, identity_element_binaryindexedtree);
}
Type_value sum(int i) // sum within [0,i)
{
if (i <= 0) {
return (Type_value)0.0;
}
if (i > size_) {
i = size_;
}
Type_value sm = 0.0;
while (i > 0) {
sm += data[i];
i -= i & -i;
}
return sm;
}
void add(int i, Type_value x) {
if (i < 0 or i >= size_) {
return;
}
++i;
while (i <= size_) {
data[i] += x;
i += i & -i;
}
}
};
/*------------------ the end of the template -----------------------*/
int N;
double p[3000];
double dp[3000][3000];
signed main() {
IOS; /* making cin faster */
SCAND(N);
REP(i, N) { scanf("%lf", &p[i]); }
dp[0][0] = 1.0;
FOR(i, 1, N + 1) {
REP(j, N + 1) {
dp[i][j] = (1.0 - p[i - 1]) * dp[i - 1][j];
if (0 < j) {
dp[i][j] += p[i - 1] * dp[i - 1][j - 1];
}
}
}
double ans = 0.0;
REP(j, N + 1) {
if (N - j < j) {
ans += dp[N][j];
}
}
printf("%.120000000lf\n", ans);
}
| #ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
#define y0 qvya13579
#define y1 qvyb24680
#define j0 qvja13579
#define j1 qvjb24680
#define next qvne13579xt
#define prev qvpr13579ev
#define INF 1000000007
#define MOD 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS \
cin.tie(0); \
ios::sync_with_stdio(false)
#define M_P make_pair
#define PU_B push_back
#define PU_F push_front
#define PO_B pop_back
#define PO_F pop_front
#define U_B upper_bound
#define L_B lower_bound
#define B_S binary_search
#define PR_Q priority_queue
#define FIR first
#define SEC second
#if __cplusplus < 201103L
#define stoi(argument_string) atoi((argument_string).c_str())
#define stoll(argument_string) atoll((argument_string).c_str())
#endif
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP_R(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define FOR(i, m, n) for (int i = ((int)(m)); i < (int)(n); ++i)
#define FOR_R(i, m, n) for (int i = ((int)(m)-1); i >= (int)(n); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SIZ(x) ((int)(x).size())
#define CIN(x) cin >> (x)
#define CIN2(x, y) cin >> (x) >> (y)
#define CIN3(x, y, z) cin >> (x) >> (y) >> (z)
#define CIN4(x, y, z, w) cin >> (x) >> (y) >> (z) >> (w)
#define CIN5(x, y, z, w, u) cin >> (x) >> (y) >> (z) >> (w) >> (u)
#define SCAND(x) scanf("%d", &(x))
#define SCAND2(x, y) scanf("%d%d", &(x), &(y))
#define SCAND3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z))
#define SCAND4(x, y, z, w) scanf("%d%d%d%d", &(x), &(y), &(z), &(w))
#define SCAND5(x, y, z, w, u) scanf("%d%d%d%d%d", &(x), &(y), &(z), &(w), &(u))
#define SCANLLD(x) scanf("%lld", &(x))
#define SCANLLD2(x, y) scanf("%lld%lld", &(x), &(y))
#define SCANLLD3(x, y, z) scanf("%lld%lld%lld", &(x), &(y), &(z))
#define SCANLLD4(x, y, z, w) scanf("%lld%lld%lld%lld", &(x), &(y), &(z), &(w))
#define SCANLLD5(x, y, z, w, u) \
scanf("%lld%lld%lld%lld%lld", &(x), &(y), &(z), &(w), &(u))
#define I64DSCAN(x) scanf("%I64d", &(x))
#define I64DSCAN2(x, y) scanf("%I64d%I64d", &(x), &(y))
#define I64DSCAN3(x, y, z) scanf("%I64d%I64d%I64d", &(x), &(y), &(z))
#define I64DSCAN4(x, y, z, w) \
scanf("%I64d%I64d%I64d%I64d", &(x), &(y), &(z), &(w))
#define I64DSCAN5(x, y, z, w, u) \
scanf("%I64d%I64d%I64d%I64d%I64d", &(x), &(y), &(z), &(w), &(u))
#define PRINTD(x) printf("%d\n", (x))
#define PRINTLLD(x) printf("%lld\n", (x))
#define PRINTI64D(x) printf("%I64d\n", (x))
#define DEBUG(argument) cerr << (#argument) << " : " << (argument) << "\n"
typedef long long int lli;
using namespace std;
bool compare_by_2nd(pair<int, int> a, pair<int, int> b) {
if (a.second != b.second) {
return a.second < b.second;
} else {
return a.first < b.first;
}
}
int ctoi(char c) {
if (c >= '0' and c <= '9') {
return (int)(c - '0');
}
return -1;
}
int alphabet_pos(char c) {
if (c >= 'a' and c <= 'z') {
return (int)(c - 'a');
}
return -1;
}
int alphabet_pos_capital(char c) {
if (c >= 'A' and c <= 'Z') {
return (int)(c - 'A');
}
return -1;
}
vector<string> split(string str, char ch) {
int first = 0;
int last = str.find_first_of(ch);
if (last == string::npos) {
last = SIZ(str);
}
vector<string> result;
while (first < SIZ(str)) {
string Ssubstr(str, first, last - first);
result.push_back(Ssubstr);
first = last + 1;
last = str.find_first_of(ch, first);
if (last == string::npos) {
last = SIZ(str);
}
}
return result;
}
int gcd(int a, int b) // assuming a,b >= 1
{
if (a < b) {
swap(a, b);
}
if (a == 0) {
return b;
}
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
long long gcd(long long a, long long b) // assuming a,b >= 1
{
if (a < b) {
swap(a, b);
}
if (a == 0LL) {
return b;
}
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
return a * b / gcd(a, b);
}
long long lcm(long long a, long long b) // assuming a,b >= 1
{
return a * b / gcd(a, b);
}
long long pow_fast(long long x, long long n_power, long long modulus) {
if (n_power == 0) {
return 1;
}
if (n_power % 2 == 0) {
return pow_fast(x * x % modulus, n_power / 2, modulus);
}
return x * pow_fast(x, n_power - 1, modulus) % modulus;
}
struct CombinationTable {
vector<vector<long long>> val;
CombinationTable(int size)
: val(size + 1, vector<long long>(size + 1)) // constructor
{
for (int i = 0; i <= size; ++i) // note that 0 <= i <= size
{
for (int j = 0; j <= i; ++j) {
if (j == 0 or j == i) {
val[i][j] = 1LL;
} else {
val[i][j] = val[i - 1][j - 1] + val[i - 1][j];
}
}
}
}
};
void print_vector(vector<int> &h) {
int L = h.size();
for (int i = 0; i < L; ++i) {
printf("%d", h[i]);
if (i != L - 1) {
printf(" ");
} else {
printf("\n");
}
}
}
void print_vector(vector<long long> &h) {
int L = h.size();
for (int i = 0; i < L; ++i) {
printf("%lld", h[i]);
if (i != L - 1) {
printf(" ");
} else {
printf("\n");
}
}
}
void print_matrix2D(vector<vector<int>> &h) {
int Ly = h.size();
int Lx = h[0].size();
for (int i = 0; i < Ly; ++i) {
for (int j = 0; j < Lx; ++j) {
printf("%d", h[i][j]);
if (j != Lx - 1) {
printf(" ");
} else {
printf("\n");
}
}
}
}
void print_matrix2D(vector<vector<long long>> &h) {
int Ly = h.size();
int Lx = h[0].size();
for (int i = 0; i < Ly; ++i) {
for (int j = 0; j < Lx; ++j) {
printf("%lld", h[i][j]);
if (j != Lx - 1) {
printf(" ");
} else {
printf("\n");
}
}
}
}
void print_matrix2D(vector<string> &h) {
int Ly = h.size();
int Lx = h[0].size();
for (int i = 0; i < Ly; ++i) {
for (int j = 0; j < Lx; ++j) {
printf("%c", h[i][j]);
}
printf("\n");
}
}
void print_binary(int val, int num_digit = 31, bool verbose = false) {
for (int k = num_digit - 1; k >= 0; --k) {
if (verbose) {
printf("%d", (val >> k) & 1);
} else {
cerr << ((val >> k) & 1);
}
}
if (verbose) {
printf("\n");
} else {
cerr << "\n";
}
}
void print_binary(long long val, int num_digit = 63, bool verbose = false) {
for (int k = num_digit - 1; k >= 0; --k) {
if (verbose) {
printf("%lld", ((val >> k) & 1));
} else {
cerr << ((val >> k) & 1);
}
}
if (verbose) {
printf("\n");
} else {
cerr << "\n";
}
}
struct UnionFind // size-based
{
vector<int> parent, treesize;
UnionFind(int size)
: parent(size), treesize(size, 1) // constructor
{
for (int i = 0; i < size; ++i) {
parent[i] = i;
}
}
int root(int x) {
if (parent[x] == x) {
return x;
}
return parent[x] = root(parent[x]);
}
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y) {
return;
}
if (treesize[x] < treesize[y]) {
parent[x] = y;
treesize[y] += treesize[x];
} else {
parent[y] = x;
treesize[x] += treesize[y];
}
}
bool sametree(int x, int y) { return root(x) == root(y); }
int gettreesize(int x) { return treesize[root(x)]; }
};
template <typename Type_value>
struct SegmentTree // Range Minimum Query (RMQ)
{
private:
int n;
vector<Type_value> node;
Type_value identity_element_segmenttree;
public:
SegmentTree(vector<Type_value> v,
Type_value identity_element_st) // constructor
{
int sz = v.size();
identity_element_segmenttree = identity_element_st;
n = 1;
while (n < sz) {
n <<= 1;
}
node.resize(2 * n - 1, identity_element_segmenttree);
for (int i = 0; i < sz; ++i) {
node[i + n - 1] = v[i];
}
for (int i = n - 2; i >= 0; --i) {
node[i] = min(node[2 * i + 1], node[2 * i + 2]);
}
}
void update(int x, Type_value val) {
x += (n - 1);
node[x] = val;
while (x > 0) {
x = (x - 1) / 2;
node[x] = min(node[2 * x + 1], node[2 * x + 2]);
}
}
Type_value getmin(int a, int b, int k = 0, int l = 0,
int r = -1) // getting minimum value in [a,b)
{
// k : index of the referred node
// [l,r) : range covered by the k-th node
if (r < 0) {
r = n;
}
if (r <= a or b <= l) {
return identity_element_segmenttree;
}
if (a <= l and r <= b) {
return node[k];
}
Type_value vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
Type_value vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
return min(vl, vr);
}
};
template <typename Type_value>
struct BinaryIndexedTree // Range Sum Query (RSQ), 0-indexed
{
private:
int size_;
vector<Type_value> data;
public:
BinaryIndexedTree(int sz, Type_value identity_element_binaryindexedtree =
0.0) // constructor
{
size_ = sz;
data.resize(sz + 1, identity_element_binaryindexedtree);
}
Type_value sum(int i) // sum within [0,i)
{
if (i <= 0) {
return (Type_value)0.0;
}
if (i > size_) {
i = size_;
}
Type_value sm = 0.0;
while (i > 0) {
sm += data[i];
i -= i & -i;
}
return sm;
}
void add(int i, Type_value x) {
if (i < 0 or i >= size_) {
return;
}
++i;
while (i <= size_) {
data[i] += x;
i += i & -i;
}
}
};
/*------------------ the end of the template -----------------------*/
int N;
double p[3000];
double dp[3000][3000];
signed main() {
IOS; /* making cin faster */
SCAND(N);
REP(i, N) { scanf("%lf", &p[i]); }
dp[0][0] = 1.0;
FOR(i, 1, N + 1) {
REP(j, N + 1) {
dp[i][j] = (1.0 - p[i - 1]) * dp[i - 1][j];
if (0 < j) {
dp[i][j] += p[i - 1] * dp[i - 1][j - 1];
}
}
}
double ans = 0.0;
REP(j, N + 1) {
if (N - j < j) {
ans += dp[N][j];
}
}
printf("%.12lf\n", ans);
}
| [
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 977,326 | 977,327 | u900727536 | cpp |
p03168 | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 10000
#define INF 1145141919364364
#define all(vec) vec.begin(), vec.end()
#define P pair<int, int>
#define S second
#define F first
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }
bool prime(int x) {
for (int i = 2; i <= sqrt(x); i++) {
if (x % i == 0)
return false;
}
return true;
}
int kai(int x) {
if (x == 0)
return 1;
return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mood) {
int res = 1;
while (y > 0) {
if (y & 1)
res = res * x % mood;
x = x * x % mood;
y >>= 1;
}
return res;
}
int comb(int x, int y) {
return kai(x) * mod_pow(kai(x - y), mod - 2, mod) % mod *
mod_pow(kai(y), mod - 2, mod) % mod;
}
int n;
long double p[3000];
long double dp[3000][3000];
long double ans;
signed main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> p[i];
dp[0][0] = 1.0;
for (int i = 0; i < n; i++) {
dp[i + 1][0] = dp[i][0] * (1.0 - p[i]);
dp[i + 1][i + 1] = dp[i][i] * p[i];
for (int j = 1; j <= i; j++) {
dp[i + 1][j] = dp[i][j - 1] * p[i] + dp[i][j] * (1.0 - p[i]);
}
}
for (int i = n / 2 + 1; i <= n; i++)
ans += dp[n][i];
printf("%.15f", ans);
} | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 10000
#define INF 1145141919364364
#define all(vec) vec.begin(), vec.end()
#define P pair<int, int>
#define S second
#define F first
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }
bool prime(int x) {
for (int i = 2; i <= sqrt(x); i++) {
if (x % i == 0)
return false;
}
return true;
}
int kai(int x) {
if (x == 0)
return 1;
return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mood) {
int res = 1;
while (y > 0) {
if (y & 1)
res = res * x % mood;
x = x * x % mood;
y >>= 1;
}
return res;
}
int comb(int x, int y) {
return kai(x) * mod_pow(kai(x - y), mod - 2, mod) % mod *
mod_pow(kai(y), mod - 2, mod) % mod;
}
int n;
long double p[3000];
long double dp[3000][3000];
long double ans;
signed main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> p[i];
dp[0][0] = 1.0;
for (int i = 0; i < n; i++) {
dp[i + 1][0] = dp[i][0] * (1.0 - p[i]);
dp[i + 1][i + 1] = dp[i][i] * p[i];
for (int j = 1; j <= i; j++) {
dp[i + 1][j] = dp[i][j - 1] * p[i] + dp[i][j] * (1.0 - p[i]);
}
}
for (int i = n / 2 + 1; i <= n; i++)
ans += dp[n][i];
printf("%.15Lf", ans);
} | [
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 977,332 | 977,333 | u277153875 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<long double>;
using vvd = vector<vd>;
void pdp(vvd dp) {
int n_ = dp.size();
cout << "----------s------------" << endl;
rep(i, n_) {
rep(j, n_) {
cout << dp.at(i).at(j);
if (j == n_ - 1) {
cout << endl;
} else {
cout << " ";
}
}
}
cout << "----------e------------" << endl;
}
int main() {
int n;
cin >> n;
int n_ = n + 1;
vd p(n_);
rep(i, n_) { cin >> p.at(i); }
vvd dp = vvd(n_, vd(n_));
dp.at(0).at(0) = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
if (j > i)
continue;
dp.at(i + 1).at(j) += dp.at(i).at(j) * p.at(i);
dp.at(i + 1).at(j + 1) += dp.at(i).at(j) * (1.0 - p.at(i));
// cout << "i: " << i << ", j: " << j << ", p_i: " << p.at(i) << endl;
// pdp(dp);
}
}
double result = 0.0;
int m = n / 2 + 1;
for (int j = 0; j < m; j++) {
result += dp.at(n).at(j);
// cout << "inc cout: " << result << endl;
}
cout << (double)result << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<long double>;
using vvd = vector<vd>;
void pdp(vvd dp) {
int n_ = dp.size();
cout << "----------s------------" << endl;
rep(i, n_) {
rep(j, n_) {
cout << dp.at(i).at(j);
if (j == n_ - 1) {
cout << endl;
} else {
cout << " ";
}
}
}
cout << "----------e------------" << endl;
}
int main() {
int n;
cin >> n;
int n_ = n + 1;
vd p(n_);
rep(i, n_) { cin >> p.at(i); }
vvd dp = vvd(n_, vd(n_));
dp.at(0).at(0) = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
if (j > i)
continue;
dp.at(i + 1).at(j) += dp.at(i).at(j) * p.at(i);
dp.at(i + 1).at(j + 1) += dp.at(i).at(j) * (1.0 - p.at(i));
// cout << "i: " << i << ", j: " << j << ", p_i: " << p.at(i) << endl;
// pdp(dp);
}
}
double result = 0.0;
int m = n / 2 + 1;
for (int j = 0; j < m; j++) {
result += dp.at(n).at(j);
// cout << "inc cout: " << result << endl;
}
cout << setprecision(10) << (double)result << endl;
}
| [
"io.output.change"
] | 977,339 | 977,340 | u631914718 | cpp |
p03168 | // In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e12;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
const ll mod = 1e9 + 7;
void faster() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const ll M = 26 + 10;
const ll N = 30 * 100 + 10;
double dp[N][N], a[N];
int main() {
faster();
int n;
cin >> n;
cout << fixed << setprecision(9);
double ans = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n; j++) {
dp[i + 1][j] = dp[i][j] * (1 - a[i]);
if (j > 0) {
dp[i + 1][j] += dp[i][j - 1] * a[i];
}
}
}
for (int i = n / 2 + 1; i <= n; i += 2) {
ans += dp[n][i];
}
cout << ans << endl;
} | // In The Name Of Allah
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e12;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
const ll mod = 1e9 + 7;
void faster() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const ll M = 26 + 10;
const ll N = 30 * 100 + 10;
double dp[N][N], a[N];
int main() {
faster();
int n;
cin >> n;
cout << fixed << setprecision(9);
double ans = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n; j++) {
dp[i + 1][j] = dp[i][j] * (1 - a[i]);
if (j > 0) {
dp[i + 1][j] += dp[i][j - 1] * a[i];
}
}
}
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << ans << endl;
} | [] | 977,347 | 977,348 | u080245145 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define pll pair<ll, ll>
#define fill(A, n) \
for (int i = 0; i < n; i++) \
cin >> A[i];
int main() {
ll n;
cin >> n;
vector<double> A(n);
fill(A, n);
vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
dp[i][0] = dp[i - 1][0] * (1 - A[i - 1]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
dp[i][j] = dp[i - 1][j] * (1 - A[i - 1]) + dp[i - 1][j - 1] * A[i - 1];
}
}
double sum = 0;
for (int i = n / 2 + 1; i <= n; i++) {
sum += dp[n][i];
}
cout << sum << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define pll pair<ll, ll>
#define fill(A, n) \
for (int i = 0; i < n; i++) \
cin >> A[i];
int main() {
ll n;
cin >> n;
vector<double> A(n);
fill(A, n);
vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
dp[0][0] = 1;
for (int i = 1; i <= n; i++)
dp[i][0] = dp[i - 1][0] * (1 - A[i - 1]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
dp[i][j] = dp[i - 1][j] * (1 - A[i - 1]) + dp[i - 1][j - 1] * A[i - 1];
}
}
double sum = 0;
for (int i = n / 2 + 1; i <= n; i++) {
sum += dp[n][i];
}
cout << setprecision(10) << sum << endl;
return 0;
}
| [
"io.output.change"
] | 977,351 | 977,352 | u419307807 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define vd vector<double>
int main() {
int n;
cin >> n;
vd prb(n + 1, 0);
prb[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> prb[i];
}
vd dp(n + 1, 0);
dp[0] = 1;
for (int i = 1; i <= n; i++) {
double prev;
for (int j = 0; j <= i; j++) {
double use = prev;
prev = dp[j];
if (j == 0)
dp[j] = dp[j] * (1 - prb[i]);
else
dp[j] = use * prb[i] + dp[j] * (1 - prb[i]);
}
}
// for(int i=0;i<=n;i++)cout<<dp[i]<<" ";
// cout<<endl;
double ans = 0;
for (int i = (n + 1) / 2; i <= n; i++)
ans += dp[i];
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define vd vector<double>
int main() {
int n;
cin >> n;
vd prb(n + 1, 0);
prb[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> prb[i];
}
vd dp(n + 1, 0);
dp[0] = 1;
for (int i = 1; i <= n; i++) {
double prev;
for (int j = 0; j <= i; j++) {
double use = prev;
prev = dp[j];
if (j == 0)
dp[j] = dp[j] * (1 - prb[i]);
else
dp[j] = use * prb[i] + dp[j] * (1 - prb[i]);
}
}
// for(int i=0;i<=n;i++)cout<<dp[i]<<" ";
// cout<<endl;
double ans = 0;
for (int i = (n + 1) / 2; i <= n; i++)
ans += dp[i];
cout << setprecision(15) << ans << endl;
} | [
"io.output.change"
] | 977,363 | 977,364 | u527834199 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int dp[n + 1][n + 1];
dp[1][0] = 1 - a[0];
dp[1][1] = a[0];
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0) {
dp[i][j] = dp[i - 1][j] * (1 - a[i - 1]);
} else if (j == i) {
dp[i][j] = dp[i - 1][j - 1] * (a[i - 1]);
} else {
dp[i][j] =
dp[i - 1][j - 1] * (a[i - 1]) + dp[i - 1][j] * (1 - a[i - 1]);
}
}
}
double sum = 0;
for (int i = n / 2 + 1; i <= n; i++) {
sum += dp[n][i];
}
cout << setprecision(10) << fixed << sum;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
double dp[n + 1][n + 1];
dp[1][0] = 1 - a[0];
dp[1][1] = a[0];
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0) {
dp[i][j] = dp[i - 1][j] * (1 - a[i - 1]);
} else if (j == i) {
dp[i][j] = dp[i - 1][j - 1] * (a[i - 1]);
} else {
dp[i][j] =
dp[i - 1][j - 1] * (a[i - 1]) + dp[i - 1][j] * (1 - a[i - 1]);
}
}
}
double sum = 0;
for (int i = n / 2 + 1; i <= n; i++) {
sum += dp[n][i];
}
cout << setprecision(10) << fixed << sum;
return 0;
} | [
"variable_declaration.type.primitive.change"
] | 977,367 | 977,368 | u200439351 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long double prob[n];
for (int i = 0; i < n; i++)
cin >> prob[i];
vector<vector<long double>> dp(n + 1, vector<long double>(n + 1, 0));
// i head and j tail
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
if (i == 0 && j == 0)
dp[i][j] = 1;
else if (i == 0) {
dp[i][j] = dp[i][j - 1] * (1 - prob[j - 1]);
} else if (j == 0) {
dp[i][j] = dp[i - 1][j] * prob[i - 1];
} else {
dp[i][j] = dp[i - 1][j] * prob[j + i - 1] +
dp[i][j - 1] * (1 - prob[i + j - 1]);
}
}
}
long double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[i][n - i];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long double prob[n];
for (int i = 0; i < n; i++)
cin >> prob[i];
vector<vector<long double>> dp(n + 1, vector<long double>(n + 1, 0));
// i head and j tail
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n - i; j++) {
if (i == 0 && j == 0)
dp[i][j] = 1;
else if (i == 0) {
dp[i][j] = dp[i][j - 1] * (1 - prob[j - 1]);
} else if (j == 0) {
dp[i][j] = dp[i - 1][j] * prob[i - 1];
} else {
dp[i][j] = dp[i - 1][j] * prob[j + i - 1] +
dp[i][j - 1] * (1 - prob[i + j - 1]);
}
}
}
long double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[i][n - i];
}
cout << setprecision(10) << ans << endl;
return 0;
} | [
"io.output.change"
] | 977,369 | 977,370 | u194359166 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
double a[n + 1], h[n + 1], t[n + 1];
a[0] = 0;
h[0] = 1;
t[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
h[i] = h[i - 1] * a[i];
t[i] = t[i - 1] * (1 - a[i]);
}
double dp[n + 1][n + 1];
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0)
dp[i][j] = t[i];
else if (i == j)
dp[i][j] = h[i];
else
dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i];
}
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << ans << "\n";
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
double a[n + 1], h[n + 1], t[n + 1];
a[0] = 0;
h[0] = 1;
t[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
h[i] = h[i - 1] * a[i];
t[i] = t[i - 1] * (1 - a[i]);
}
double dp[n + 1][n + 1];
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0)
dp[i][j] = t[i];
else if (i == j)
dp[i][j] = h[i];
else
dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i - 1][j - 1] * a[i];
}
}
double ans = 0;
for (int i = n / 2 + 1; i <= n; i++) {
ans += dp[n][i];
}
cout << setprecision(10) << ans << "\n";
} | [
"io.output.change"
] | 977,379 | 977,380 | u222329105 | cpp |
p03168 | #pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;
#define pb(x) push_back(x)
#define ts(x) to_string(x)
#define ti(x) stoi(x)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define Mp make_pair
#define tab '\t'
#define sep ' '
#define mine(v) *min_element(all(v))
#define maxe(v) *max_element(all(v))
#define error(x) cerr << #x << " = " << x << endl
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define file_io \
freopen("in.txt", "r+", stdin); \
freopen("out.txt", "w+", stdout);
#define endl "\n"
inline ll input() {
ll n;
cin >> n;
return n;
}
ll poww(ll a, ll b, ll md) {
return (!b ? 1
: (b & 1 ? a * poww(a * a % md, b / 2, md) % md
: poww(a * a % md, b / 2, md) % md));
}
const int MAXN = 3e3 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;
double p[MAXN];
double dp[MAXN][MAXN];
ll n;
int main() {
fast_io;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[i][0] = dp[i - 1][0] * ((double)1 - p[i]);
for (int j = 1; j <= i; j++) {
dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * ((double)1 - p[i]);
}
}
/*for (int i = 1; i <= n;i++){
cout << ":: ";
for (int j = 0;j <= n;j++){
cout << dp[i][j] << tab;
}
cout << endl;
}*/
double ans = 0;
for (int i = (n + 1) / 2; i <= n; i++) {
ans += dp[n][i];
}
cout << ans << endl;
}
| #pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;
#define pb(x) push_back(x)
#define ts(x) to_string(x)
#define ti(x) stoi(x)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define Mp make_pair
#define tab '\t'
#define sep ' '
#define mine(v) *min_element(all(v))
#define maxe(v) *max_element(all(v))
#define error(x) cerr << #x << " = " << x << endl
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define file_io \
freopen("in.txt", "r+", stdin); \
freopen("out.txt", "w+", stdout);
#define endl "\n"
inline ll input() {
ll n;
cin >> n;
return n;
}
ll poww(ll a, ll b, ll md) {
return (!b ? 1
: (b & 1 ? a * poww(a * a % md, b / 2, md) % md
: poww(a * a % md, b / 2, md) % md));
}
const int MAXN = 3e3 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;
double p[MAXN];
double dp[MAXN][MAXN];
ll n;
int main() {
fast_io;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
dp[i][0] = dp[i - 1][0] * ((double)1 - p[i]);
for (int j = 1; j <= i; j++) {
dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * ((double)1 - p[i]);
}
}
/*for (int i = 1; i <= n;i++){
cout << ":: ";
for (int j = 0;j <= n;j++){
cout << dp[i][j] << tab;
}
cout << endl;
}*/
double ans = 0;
for (int i = (n + 1) / 2; i <= n; i++) {
ans += dp[n][i];
}
cout << setprecision(15) << ans << endl;
}
| [
"io.output.change"
] | 977,381 | 977,382 | u838685314 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
/*
g++ -std=c++11 i-coins.cpp -o k
*/
int main() {
int i, j, N;
cin >> N;
float p[N];
float m[N + 1][N + 1];
for (i = 0; i < N; i++) {
m[0][i] = 0.0;
cin >> p[i];
}
m[0][0] = 1.0;
m[0][N] = 0.0;
for (i = 1; i <= N; i++) {
// coin i is indexed i-1
m[i][0] = m[i - 1][0] * (1.0 - p[i - 1]);
// cout << m[i][0] << " ";
for (j = 1; j <= N; j++) {
// j heads
m[i][j] = m[i - 1][j - 1] * p[i - 1] + m[i - 1][j] * (1.0 - p[i - 1]);
// cout << m[i][j] << " ";
}
// cout << endl;
}
float o = 0.0;
for (i = N; i > N / 2; i--) {
o += m[N][i];
}
cout.precision(numeric_limits<float>::max_digits10);
cout << o << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
/*
g++ -std=c++11 i-coins.cpp -o k
*/
int main() {
int i, j, N;
cin >> N;
double p[N];
// m[coins i][heads j]
double m[N + 1][N + 1];
for (i = 0; i < N; i++) {
m[0][i] = 0.0;
cin >> p[i];
}
m[0][0] = 1.0;
m[0][N] = 0.0;
for (i = 1; i <= N; i++) {
// coin i is indexed i-1 in p
m[i][0] = m[i - 1][0] * (1.0 - p[i - 1]);
// cout << m[i][0] << " ";
for (j = 1; j <= N; j++) {
// j heads
m[i][j] = m[i - 1][j - 1] * p[i - 1] + m[i - 1][j] * (1.0 - p[i - 1]);
// cout << m[i][j] << " ";
}
// cout << endl;
}
double o = 0.0;
for (i = N; i > N / 2; i--) {
o += m[N][i];
}
cout.precision(numeric_limits<double>::max_digits10);
cout << o << endl;
return 0;
}
| [
"variable_declaration.type.primitive.change",
"io.output.change"
] | 977,387 | 977,388 | u758170215 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
double dp[3000][3000];
double p[3000], ans;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
dp[i][j] += dp[i - 1][j] * (1 - p[i]);
dp[i][j + 1] += dp[i - 1][j] * p[i];
}
}
for (int i = n; i > n / 2; i--)
ans += dp[n][i];
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
double dp[3000][3000];
double p[3000], ans;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
dp[i][j] += dp[i - 1][j] * (1 - p[i]);
dp[i][j + 1] += dp[i - 1][j] * p[i];
}
}
for (int i = n; i > n / 2; i--)
ans += dp[n][i];
cout << setprecision(1000000) << ans;
} | [
"io.output.change"
] | 977,389 | 977,390 | u809374784 | cpp |
p03168 | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
using ll = long long;
const int INF = 1e9 + 5;
const int N = 1000 + 5;
const int mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
// freopen("input.txt","r",stdin);
int n;
cin >> n;
vector<double> dp(n + 1);
dp[0] = 1;
for (int coin = 0; coin < n; ++coin) {
double val;
cin >> val;
for (int i = coin + 1; i >= 0; --i) {
dp[i] = (!i ? 0 : dp[i - 1] * val) + dp[i] * (1 - val);
}
}
double ans = 0;
for (int head = (n + 1) / 2; head <= n; ++head) {
ans += dp[head];
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
using ll = long long;
const int INF = 1e9 + 5;
const int N = 1000 + 5;
const int mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
// freopen("input.txt","r",stdin);
int n;
cin >> n;
vector<double> dp(n + 1);
dp[0] = 1;
for (int coin = 0; coin < n; ++coin) {
double val;
cin >> val;
for (int i = coin + 1; i >= 0; --i) {
dp[i] = (!i ? 0 : dp[i - 1] * val) + dp[i] * (1 - val);
}
}
double ans = 0;
for (int head = (n + 1) / 2; head <= n; ++head) {
ans += dp[head];
}
cout << setprecision(10) << ans;
return 0;
}
| [
"io.output.change"
] | 977,401 | 977,402 | u254886300 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.