题意:初始有加拿大的$1000,给出每天一个美国美元与加拿大美元的兑换率,每次兑换需要花费3%的手续费,并且还会把小于美分的给省去,问最后最多有多少加拿大美元。
题解:dp[i][0]为第i天最多有多少加拿大美元,dp[i][1]为第i天最多有多少美国美元,
dp[i][0]=max(dp[i-1][0],update(dp[i-1][1]*per*0.97));
dp[i][1]=max(update(dp[i-1][0]/per*0.97),dp[i-1][1]);
update是舍去美分以下的数。

1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 double dp[400][2]; 6 double update(double x) 7 { 8 x*=100.0; 9 int y=(int)x; 10 return y/100.0; 11 } 12 int main() 13 { 14 int n; 15 while(scanf("%d",&n),n) 16 { 17 dp[0][0]=1000.0; 18 dp[0][1]=0; 19 for(int i=1;i<=n;i++) 20 { 21 double per; 22 scanf("%lf",&per); 23 dp[i][0]=max(dp[i-1][0],update(dp[i-1][1]*per*0.97)); 24 dp[i][1]=max(update(dp[i-1][0]/per*0.97),dp[i-1][1]); 25 } 26 printf("%.2lf\n",dp[n][0]); 27 } 28 return 0; 29 }