Ultraviolet A 301 Transportation, a pure dfs violence by the railway company

Source: Internet
Author: User

The question is hard to understand.

Given the railway capacity, number of stations, and several orders, it is required to determine how much profit is maximized.

I want to be greedy, but it cannot be determined that it is the optimal solution.

If you use dfs, select or do not select the number of current users for each site. If you want to select the number, add the number of users for each site to determine whether there will be superhumans, the next round of dfs will not be selected, and then the number of people will be reduced to enter the unselected dfs.

This question is said to have timed out when marking with arrays...

Code:

 

#include <cstdio>     const int maxn = 30;  int cap, num, ord, ans;  int cnt[10];    struct Order {      int s;      int e;      int p;  };  Order o[maxn];    bool judge() {      for (int i = 0; i < num; i++)          if (cnt[i] > cap)              return false;      return true;  }    void dfs(int d, int sum) {      if (sum > ans) ans = sum;      if (d >= ord) return;      for (int i = o[d].s; i < o[d].e; i++)          cnt[i] += o[d].p;      if (judge())                    //choose           dfs(d + 1, sum + o[d].p * (o[d].e - o[d].s));      for (int i = o[d].s; i < o[d].e; i++)          cnt[i] -= o[d].p;      dfs(d + 1, sum);                //not choose   }    int main() {      while (scanf("%d%d%d", &cap, &num, &ord) && (cap || num || ord)) {          for (int i = 0; i < num; i++)              cnt[i] = 0;          for (int i = 0; i < ord; i++)              scanf("%d%d%d", &o[i].s, &o[i].e, &o[i].p);          if (!cap || !num || !ord) {              printf("0\n");              continue;          }          ans = 0;          dfs(0, 0);          printf("%d\n", ans);      }      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.