UVA 812 (violence)

Source: Internet
Author: User

Test instructions: There are n shelves of B goods, and then from left to right to give the price of the goods on each shelf, to be sold at a flat price of 10, ask if the Buy form is a stack, to buy a goods must be his left to buy things to be able to ask the maximum profit is how much, to buy how many goods to achieve maximum profit, Output all possible conditions (up to 10) in dictionary order.

Problem: Water, violence out of all circumstances.

Example of the second set of samples:

3 10 9) 10 10

Number of purchases possible: 2 4 5
9 17 24 30 30 24 24 30 24

Number of purchases possible: 4 5 8

Then there are 6 numbers of permutations combined to get all the solutions. Note the number may be 0.

#include <stdio.h> #include <string.h> #include <algorithm>using namespace std;const int M = 1005;const int N = 55;int Box[n], N, Num[n][n], mp[m], num2[n];void dfs (int cur, int sum) {if (cur >= N) {mp[sum] = 1;return;} for (int i = 0; i < num2[cur]; i++) DFS (cur + 1, sum + num[cur][i]);} int main () {int cas = 0;while (scanf ("%d", &n) = = 1 && N) {memset (MP, 0, sizeof (MP)), int temp, res = 0;for (in t i = 0; I < n;  i++) {scanf ("%d", &temp), int sum = 0, Maxx = 0;for (int j = 0; J < temp; J + +) {scanf ("%d", &box[j]); sum + = 10- Box[j];maxx = max (Maxx, sum);} Res + = Maxx;sum = 0;int cnt = 0;if (Maxx = = 0) num[i][cnt++] = 0;for (int j = 0; J < temp; J + +) {sum + = 10-box[j];if ( sum = = Maxx) num[i][cnt++] = j + 1;} Num2[i] = cnt;} if (CAS) printf ("\ n");p rintf ("Workyards%d\n", ++cas);p rintf ("Maximum profit is%d.\n", res);p rintf ("Number of the pruls to BU Y: ");d FS (0, 0); temp = 0;for (int i = 0; i < M; i++) {if (temp = =) break;if (Mp[i]) {temp++;p rintf (" %d ", i);}} printf ("\ n");} return 0;}


UVA 812 (violence)

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.