Skip to content

Commit

Permalink
Accepted
Browse files Browse the repository at this point in the history
  • Loading branch information
volzkzg committed Jul 26, 2013
1 parent 705c48d commit e61cf7e
Showing 1 changed file with 28 additions and 33 deletions.
61 changes: 28 additions & 33 deletions 422.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,34 @@
using namespace std;

const int MAX = 3333;
double p[MAX],f[MAX][MAX],t,now;
int n;

void init()
{
cin >> n >> t;
for (int i = 1; i <= n; ++i) cin >> p[i];
}

void solve()
{
for (int y = 1; y <= n; ++y)
for (int x = y-1; x >= 0; --x) {
now = (double)1 - p[x+1];
f[x][y] = (y - x + t) + (y - x) * p[x+1];
for (int z = x + 2; z <= y; ++z) {
f[x][y] += now * p[z] * (y - z + 1 + f[z-1][y]);
now *= ((double)1 - p[z]);
}
f[x][y] /= ((double)1-p[x+1]);
}
cout << setiosflags(ios::fixed)
<< setprecision(8)
<< f[0][n] << endl;
}
double p[MAX],q[MAX],f[MAX],now,add;
int n,t;

int main()
{
freopen("test.in","r",stdin);
ios::sync_with_stdio(false);

init();
solve();

return 0;
}
ios::sync_with_stdio(false);

cin >> n >> t;
for (int i = 1; i <= n; ++i) {
cin >> p[i];
q[i] = 1 - p[i];
}
for (int i = n-1; i >= 0; --i) {
for (int j = 1; i + j <= n; ++j) {
if (j == 1) {
now = 1 + t + p[i+1] + q[i+1] * f[i+1];
f[i] = now / q[i+1];
add = q[i+1];
} else {
add *= q[i+j];
now += 2 + add * (f[i+j] - f[i+j-1] - 1);
f[i] = min(f[i],now / q[i+1]);
}
}
}
cout << setiosflags(ios::fixed)
<< setprecision(7)
<< f[0] << endl;

return 0;
}

0 comments on commit e61cf7e

Please sign in to comment.