Ultraviolet-812 trade on verweggistan

Source: Internet
Author: User

First, give you a pair of goods, then give you n and N numbers to indicate the price, 10-The price is the profit

Only the first I can be obtained at a time. The maximum profit corresponds to several goods, and no more than 10 solutions can be obtained.

Idea: first, calculate the maximum profit, then store all the solutions, and then find out all the possibilities.

#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>#include <queue>#include <vector>#include <set>using namespace std;const int MAXN = 100;int w, val[MAXN][MAXN];set<int > ans;vector<int > p[MAXN];void cal(int n, int sum) {if (n == w) {ans.insert(sum);return;}for (int i = 0; i < p[n].size(); i++)cal(n+1, sum+p[n][i]);}void solve() {ans.clear();int valMax[MAXN], valSum, pro;valSum = 0;memset(valMax, 0, sizeof(valMax));for (int i = 0; i < w; i++) {p[i].clear();pro = 0;for (int j = 1; j <= val[i][0]; j++) {pro += 10 - val[i][j];valMax[i] = max(valMax[i], pro);}valSum += valMax[i];if (valMax[i] == 0)p[i].push_back(0);pro = 0;for (int j = 1; j <= val[i][0]; j++) {pro += 10 - val[i][j];if (valMax[i] == pro)p[i].push_back(j);}}cal(0, 0);printf("Maximum profit is %d.\n", valSum);printf("Number of pruls to buy:");int cnt = 0;for (set<int>::iterator i = ans.begin(); i != ans.end() && cnt != 10; i++, cnt++) printf(" %d", *i);printf("\n");}int main() {int t = 0;while (scanf("%d", &w) != EOF && w) {int b;for (int i = 0; i < w; i++) {scanf("%d", &val[i][0]);for (int j = 1; j <= val[i][0]; j++)scanf("%d", &val[i][j]);}if (t)printf("\n");printf("Workyards %d\n", ++t);solve();}return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.