Files
python/GESP/Mkx/ZC_1_1.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

36 lines
660 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 15;
const int INF = 0x3f3f3f3f;
int a[N];
/*
12 20 30 40 25 60 70 80 90 11
21
34
*/
// m是剩余多少公里 sum已经花了多少钱
// int sum=dfs(int m) 要走m公里最少需要多少钱=sum
int dfs(int m) { // 要走m公里最少需要花多少钱
if (m == 0)
return 0;
int res = INF;
for (int i = 1; i <= min(m, 10); i++)
res = min(res, dfs(m - i) + a[i]);
return res;
}
int main() {
for (int i = 1; i <= 10; i++)
cin >> a[i];
int m; // 要走多少公里
cin >> m;
// 递归
cout << dfs(m) << endl;
return 0;
}