赞
踩
- #include <bits/stdc++.h>
- using namespace std;
- struct node
- {
- double v, w, dwv;
- }
- a[101];
- bool cmp(node a, node b)
- {
- return a.dwv > b.dwv;
- }
- int main()
- {
- int n;
- double jg = 0, room;
- cin >> n >> room;
- for (int i = 0; i < n; i++)
- {
- cin >> a[i].v >> a[i].w;
- a[i].dwv = a[i].w * 1.0 / a[i].v / 1.0;
- }
- sort(a, a + n, cmp);
- for (int i = 0; i < n && room>0; i++)
- {
- if (room < a[i].v)
- {
- jg += room * a[i].dwv;
- room = 0;
- }
- else
- {
- jg += a[i].w;
- room -= a[i].v;
- }
- }
- cout << fixed << setprecision(2) << jg;
- }
- #include <bits/stdc++.h>
- using namespace std;
- int v[1001], w[1001], bag[1001];
- int main()
- {
- int n, weight;
- cin >> n >> weight;
- for (int i = 1; i <= n; i++)
- cin >> w[i] >> v[i];
- for (int i = 1; i <= n; i++)
- for (int j = weight; j >= w[i]; j--)
- bag[j] = max(bag[j], bag[j - w[i]] + v[i]);
- cout << bag[weight] << endl;
- return 0;
- }
- #include <bits/stdc++.h>
- using namespace std;
- int bag[1001], n, t;
- void work()
- {
- long long x, n, t;
- cin >> n >> t;
- bag[0] = 1;
- for (int i = 0; i < n; i++)
- {
- cin >> x;
- for (int j = t; j >= x; j--)
- bag[j] = (bag[j] + bag[j - x]) % 1000000007;
- }
- cout << bag[t] << endl;
- }
- int main()
- {
- work();
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。