HDU-2546 飯卡
阿新 • • 發佈:2018-11-16
連結:
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <cstdlib> #include <cstring> #include <string> using namespace std; #define N 100 int dp[N], v[N], w[N], V, W; void bag01(int v, int w) { for (int i = V; i >= v; i--) { dp[i] = max(dp[i], dp[i - v] + w); } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, num; while (cin >> n && n) { for (int i = 0; i < n; i++) { cin >> v[i]; } cin >> num; V = num - 5; sort(v, v + n); for (int i = 0; i < n - 1; i++) { bag01(v[i], v[i]); } cout << num - dp[V] - v[n - 1] << endl; } return 0; }