36 lines
660 B
C++
36 lines
660 B
C++
|
|
#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;
|
|||
|
|
}
|