2 个赞
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
int n, I, J, K, L, T;
map<int , int >f;
int dfs(int n) {
if (n == 1)return L;
if (n == 0)return 0;
if (f.count(n))return f[n];
int x = n * L;
x = min(x, dfs(n / 2) + I + n % 2 * L);
x = min(x, dfs((n + 1) / 2) + I + n % 2 * L);
x = min(x, dfs(n / 3) + J + (n - n / 3 * 3) * L);
x = min(x, dfs((n + 2) / 3) + J + ((n + 2) / 3 * 3 - n) * L);
x = min(x, dfs(n / 5) + K + (n - n / 5 * 5) * L);
x = min(x, dfs((n + 4) / 5) + K + ((n + 4) / 5 * 5 - n) * L);
return f[n] = x;
}
signed main() {
cin >> T;
while (T--) {
cin>>n>>I>>J>>K>>L;
f.clear();
cout << dfs(n) << endl;
}
}
4 个赞

