poj 3639 dp

来源:互联网 发布:linux编程基础 编辑:程序博客网 时间:2024/06/05 02:36
Exchange Rates
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2478 Accepted: 875

Description

Now that the Loonie is hovering about par with the Greenback, you have decided to use your $1000 entrance scholarship to engage in currency speculation. So you gaze into a crystal ball which predicts the closing exchange rate between Canadian and U.S. dollars for each of the next several days. On any given day, you can switch all of your money from Canadian to U.S. dollars, or vice versa, at the prevailing exchange rate, less a 3% commission, less any fraction of a cent.

Assuming your crystal ball is correct, what's the maximum amount of money you can have, in Canadian dollars, when you're done?

Input

The input contains a number of test cases, followed by a line containing 0. Each test case begins with 0 < d ≤ 365, the number of days that your crystal ball can predict. d lines follow, giving the price of a U.S. dollar in Canadian dollars, as a real number.

Output

For each test case, output a line giving the maximum amount of money, in Canadian dollars and cents, that it is possible to have at the end of the last prediction, assuming you may exchange money on any subset of the predicted days, in order. 

Sample Input

31.05000.93000.990021.05001.10000

Sample Output

1001.60

1000.00

#include <iostream>#include <vector>#include <map>#include <set>#include <queue>#include <stack>#include <algorithm>#include <cstdio>#include <string>#include <cstring>#include <cmath>#include <ctime>using namespace std;#define LL long long#define clr(s,x) memset(s,x,sizeof(s))#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const double PI = acos(-1.0);const LL mod = 1e9+7;const int maxn=1005;double dp[maxn][2];double per[maxn];double get_ans(double x){    x=x*100.0;    int xx=(int)x;    return xx/100.0;}int main(){    int n;    while(cin>>n){        clr(dp,0);        clr(per,0);        if(n==0)break;        for(int i=1;i<=n;i++){            cin>>per[i];        }        dp[0][0]=1000.0;// ca        dp[0][1]=0;//us        for(int i=1;i<=n;i++){            dp[i][0]=max(dp[i-1][0],get_ans(dp[i-1][1]*per[i]*0.97));            dp[i][1]=max(dp[i-1][1],get_ans(dp[i-1][0]/per[i]*0.97));        }        printf("%.2f\n",dp[n][0]);    }    return 0;}


0 0
原创粉丝点击