Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #define N 1005
- #define M 105
- #define eps (1e-5)
- using namespace std;
- int a[N], n, from[N][M];
- double dp[N][M];
- void ans(int pos, int pos2) {
- if (pos)
- ans(pos - 1, from[pos][pos2]);
- cout << pos2 << " ";
- }
- int main() {
- cin >> n;
- for (int i = 0; i < n; i++)
- cin >> a[i];
- for (int i = 1; i < n; i++)
- for (int j = 1; j <= a[i - 1]; j++)
- for (int k = 1; k <= a[i]; k++) {
- if (dp[i][k] + eps < dp[i - 1][j] + double(k) / j) {
- dp[i][k] = dp[i - 1][j] + double(k) / j;
- from[i][k] = j;
- }
- }
- double res = 0;
- int pos;
- for (int i = 1; i <= a[n - 1]; i++)
- if (dp[n - 1][i] > res + eps) {
- res = dp[n - 1][i];
- pos = i;
- }
- cout.precision(3);
- cout << fixed << res << endl;
- ans(n - 1, pos);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement