JSCPC f ( 期望dp
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
double dp[2000010];
int n;
string s;
//可能要特判 b == 1的情况
//有 a 个 材料 ,每 b 个 合成一个,俩种方案,
//1 . 双倍产出 p
//2 . 返还材料 q
int a,b;
double p,q;
double res = 0;
int main(){cin>>a>>b>>p>>q;p /= 100;q /= 100;dp[0] = 0;if(b == 1){double t1 = 1 + p;double t2 = (1.0 - pow(q,11000)) / (1-q) - 11000.0 * pow(q,11000);printf("%.10lf" , a * max(t1,t2));return 0;}for(int i = 1 ; i <= a ; i++){dp[i] = 0;if(i >= b) dp[i] = p * (dp[i-b] + 2) + (1-p) * (dp[i-b] + 1);double t = 0;if(i >= b){t += (dp[i-b] + 1) * (1-q) + (dp[i - b + 1] + 1) * q;;}// cout<<dp[i]<<" "<<t<<"\n";// t += (dp[i - b + 1] + 1) * q;dp[i] = max(dp[i] , t);res = max(res, dp[i]);}printf("%.10lf" ,res);}
Problem - F - Codeforces