80分求助

P1968 美元汇率

Celius @ 2023-01-29 13:22:02

#include<bits/stdc++.h>
using namespace std;
const int maxN=105;
double dp[maxN][2];
int n,a[maxN];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    dp[1][0]=100;
    dp[1][1]=a[1];
    for(int i=2; i<=n; i++)
    {
        dp[i][0]=max(dp[i-1][0],dp[i-1][1]/a[i]*100);
        dp[i][1]=max(dp[i-1][1],dp[i-1][0]*a[i]/100);
    }
    cout<<dp[n][0];
    return 0;
}

by ericdan666 @ 2024-08-20 22:06:29

double dollar = 100, mark = 0;
for(int i = 1; i <= n; i++)
{
mark = max(mark, dollar * A);
dollar = max(dollar, mark / A);
}

|