P1412 经营与开发 · znzryb
## 思路讲解
```cpp
// 以i为起点,初始值为w,所能够获得的最大收益
vdb dp(N+5);
ROF(i,N,1){
auto [type,val]=A[i];
if(type==1){
dp[i]=max(dp[i+1],dp[i+1]*(1-cost*0.01)+val*W);
}else{
dp[i]=max(dp[i+1],dp[i+1]*(1+grow*0.01)-val*W);
}
}
cout<<fsp(2)<<dp[1]<<"\n";
```
这道题目,我认为关键点在这里,因此我们推一下
$W\times val+W\times (1-0.01\times cost)\times val_2 +W\times (1-0.01\times cost)^2\times val_3$
不难发现,无论怎么样操作,一个星球的收益一定是一个连乘的式子,因此上述操作就不难理解了。
## AC代码
[https://vjudge.net/solution/62959677](https://vjudge.net/solution/62959677)
::: 源代码
```cpp
// by Gospel_rock
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define PB push_back
#define EB emplace_back
#define EM emplace
#define FI first
#define SE second
#define pct __builtin_popcountll
#define ctz __builtin_ctzll
#define SZ(a) ((long long) a.size())
#define FOR(i, a, b) for (long long i = (a); i <= (b); ++i)
#define ROF(i, a, b) for (long long i = (a); i >= (b); --i)
#define debug(var) cerr << #var <<":"<<var<<"\n";
#define cend cerr<<"\n-----------\n"
#define lson(var) (var<<1)
#define rson(var) (var<<1|1)
#define fsp(x) fixed<<setprecision(x)
#define minn(vec) *min_element(vec.begin(),vec.end())
#define maxx(vec) *max_element(vec.begin(),vec.end())
using namespace std;
#ifdef LOCAL
template<typename T> void _print(T x) { cerr << x; }
template<typename T> void _print(vector<T> v) { cerr << "[ "; for (T i : v) _print(i), cerr << " "; cerr << "]"; }
template<typename T> void _print(set<T> s) { cerr << "{ "; for (T i : s) _print(i), cerr << " "; cerr << "}"; }
template<typename T, typename U> void _print(pair<T, U> p) { cerr << "{"; _print(p.first); cerr << ", "; _print(p.second); cerr << "}"; }
template<typename T, typename U> void _print(map<T, U> m) { cerr << "{ "; for (auto &p : m) _print(p), cerr << " "; cerr << "}"; }
template<typename T> void _print(vector<vector<T>> v){cerr<<"{\n";for (auto i : v) _print(i), cerr << "\n";cerr<<" }";}
#endif
using ll = long long;using ull = unsigned long long;
using DB=double;using LD=long double;
using i128 = __int128;
using pdd = pair<DB,DB>;using plb = pair<ll,bool>;
using pll = pair<ll,ll>;using vll=vector<ll>;using vb=vector<bool>;
using tll = tuple<ll,ll,ll>;using vii=vector<int>;
using vpll = vector<pll>;using vtll = vector<tll>;
using vdb = vector<DB>;using vc=vector<char>;
using arr3 = array<ll,3> ;using arr2 = array<ll,2>;
using CD=complex<double>;
static constexpr ll MAXN=(ll)1e6+10,INF=(ll)1e17+3; // 1e17+3是素数 1e18+9是素数
static constexpr ll mod=(ll)1e9+7; // 998244353;
static constexpr double eps=1e-8;const double pi=acos(-1.0);
ll N,M,Q,X,T,lT,W;
inline void __();
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
// cin>>lT;
// while(lT--)
__();
return 0;
}
/*
*/
struct planet{
ll type,val;
};
inline void __(){
ll cost,grow;
cin>>N>>cost>>grow>>W;
vector<planet> A(N+5);
FOR(i,1,N){
cin>>A[i].type>>A[i].val;
}
// 以i为起点,初始值为w,所能够获得的最大收益
vdb dp(N+5);
ROF(i,N,1){
auto [type,val]=A[i];
if(type==1){
dp[i]=max(dp[i+1],dp[i+1]*(1-cost*0.01)+val*W);
}else{
dp[i]=max(dp[i+1],dp[i+1]*(1+grow*0.01)-val*W);
}
}
cout<<fsp(2)<<dp[1]<<"\n";
}
/*
AC
https://vjudge.net/solution/62959677
*/
```
:::
## 心路历程(WA,TLE,MLE……)