4391: GESP C++ 六级 3小杨买饮料202309
内存限制:128 MB
时间限制:1.000 S
评测方式:文本比较
命题人:
提交:1
解决:1
题目描述
样例输入 复制
5 100
100 2000
2 50
4 40
5 30
3 20
样例输出 复制
9
提示
#include <iostream> using namespace std; const int INF = 1000000000; int cost[2001]; int main() { int N = 0, L = 0; cin >> N >> L; cost[0] = 0; for (int i = 1; i <= L; i++) cost[i] = INF; for (int i = 0; i < N; i++) { int c = 0, l = 0; cin >> c >> l; for (int j = L; j >= 0; j--) cost[j] = min(cost[j], cost[max(j - l, 0)] + c); } if (cost[L] == INF) cout << "no solution" << endl; else cout << cost[L] << endl; return 0; }