Ultraviolet A 812-Trade on Verweggistan (violent)

Source: Internet
Author: User

Question connection: Ultraviolet A 812-Trade on Verweggistan


N sequences are given. Each sequence is given k, indicating that there are k elements. Each row can only be retrieved from the beginning, taking I (I ≤ k ), now we need to remove c [I] before each sequence, ensure that sum = Σ | 10-num | (num is the set of the selected number) is the maximum, and output the number that can be selected, if the number is greater than 10, the minimum output value is 10.


Solution: traverse each sequence once to find out the maximum value and the number that can constitute the maximum value. Note that you can take 0 and then recursively solve all composition conditions.


#include 
 
  #include 
  
   #include 
   
    #include using namespace std;const int tmp = 10;const int N = 60;const int M = 1005;const int INF = 0x3f3f3f3f;int n, ans, cnt[M];vector
    
      v[N];void init() {ans = 0;memset(cnt, 0, sizeof(cnt));int m, num;for (int i = 0; i < n; i++) {scanf("%d", &m); v[i].clear();int sum = 0, Max = 0;v[i].push_back(0);for (int j = 0; j < m; j++) {scanf("%d", &num);sum += (tmp - num);if (sum > Max) {v[i].clear();v[i].push_back(j+1);Max = sum;} else if (sum == Max) {v[i].push_back(j+1);}}ans += Max;}}void dfs(int d, int s) {if (d >= n) {cnt[s] = 1;return ;}int top = v[d].size();for (int i = 0; i < top; i++) {dfs(d + 1, s + v[d][i]);}}void solve() {dfs(0, 0);int c = 0;for (int i = 0; i < M; i++) {if (c >= tmp) break;if (cnt[i]) {printf(" %d", i);c++;}}printf("\n");}int main() {int cas = 0;while (scanf("%d", &n) == 1 && n) {init();if (cas) printf("\n");printf("Workyards %d\n", ++cas);printf("Maximum profit is %d.\n", ans);printf("Number of pruls to buy:");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.