AtCoder Grand Contest 044

Posted lightac

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AtCoder Grand Contest 044相关的知识,希望对你有一定的参考价值。

比赛爆零==

技术图片

 

 简单来说 题意就是 给一个N 然后给了4种操作的代价 求最小的代价。用DFS搜索

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--) {
		ll n, a, b, c, d;
		cin >> n >> a >> b >> c >> d;
		std::vector<pair<int, ll>> ops;
		// ops.emplace_back(2, a);
		ops.push_back(make_pair(2, a));
		ops.push_back(make_pair(3, b));
		ops.push_back(make_pair(5, c));
		const ll inf = 4e18;
		map<ll, ll> mp;
		mp[0] = 0;
		mp[1] = d;
		function<ll(ll)> DFS = [&](ll x) {
			if(mp.find(x) != mp.end()) {	//如果找到了返回这个值
				return mp[x];
			}
			ll ret = inf;
			//不进行判断会wa
			if((long double)d * (long double)x < ret) {
				ret = d * x;
			}
			for(auto& p : ops) {
				int num = p.first;
				ll cost = p.second;
				//分成了两种情况:第一种是减1;第二种是加1
				ret = min(ret, DFS(x / num) + cost + d * (x % num));
				if(x % num != 0) {
					ret = min(ret, DFS(x / num + 1) + cost + d * (num - x % num));
				}
			}
			return mp[x] = ret;
		};
		cout << DFS(n) << endl;
	}
	return 0;
}

 

以上是关于AtCoder Grand Contest 044的主要内容,如果未能解决你的问题,请参考以下文章

AtCoder Grand Contest 044 题解

markdown AtCoder Grand Contest 016

AtCoder Grand Contest 005

AtCoder Grand Contest 006

AtCoder Grand Contest 008 题解

AtCoder Grand Contest 025 Problem D