Hdoj 4971 a simple brute force problem. [maximum closing weight --> Minimum Cut]

Source: Internet
Author: User

Question: hdoj 4971 a simple brute force problem.


Question:Given n tasks and M technologies, several technologies are required to complete a task. To complete a task, you have a bonus. Learning a technology requires money,There is a parent-child relationship between technologies. A technology may need to learn other technologies first,Then, how many tasks do you choose to achieve the greatest benefit?


Analysis: The black text part of the question is a standard closed right problem. The key to this question is the relationship between technologies, which leads many people to think of DP and tree-like DP.

In fact, it is a closed-Permission question template. The official question is: if there is a mutual relationship between technologies, it needs to be scaled down. In fact, it does not need to be scaled down.

Graph creation:


# Include <cstdio> # include <algorithm> # include <vector> # include <queue> # include <cstring> const int n = 200; using namespace STD; const int INF = 0x3f3f3f; # define del (a, B) memset (a, B, sizeof (A) struct node {int from, to, Cap, flow ;}; vector <int> V [N]; vector <node> E; int vis [N], cur [N]; void add_node (int from, int to, int cap) {e. push_back (node) {from, to, Cap, 0}); E. push_back (node) {to, from, 0, 0}); int TMP = E. size (); V [from]. push_back (tmp-2); V [to]. push_back (tmp-1);} bool BFS (int s, int t) {del (VIS,-1); queue <int> q; q. push (s); vis [s] = 0; while (! Q. empty () {int x = Q. front (); q. pop (); For (INT I = 0; I <V [X]. size (); I ++) {node TMP = E [V [x] [I]; If (vis [TMP. to] <0 & TMP. cap> TMP. flow) // The second condition ensures {vis [TMP. to] = vis [x] + 1; q. push (TMP. to) ;}}} if (vis [T]> 0) return true; return false;} int DFS (int o, int F, int T) {If (O = T | f = 0) // returns F; int A = 0, ANS = 0; For (Int & I = cur [O]; I <V [O]. size (); I ++) // note the preceding '&', which is an important optimization {node & TMP = E [V [O] [I]; if (vis [TMP. to] = (vis [O] + 1) & (A = DFS (TMP. to, min (F, TMP. cap-tmp.flow), t)> 0) {TMP. flow + = A; E [V [O] [I] ^ 1]. flow-= A; // save graph mode ans + = A; F-= A; If (F = 0) // note break optimization;} return ans; // optimization} int dinci (int s, int t) {int ans = 0; while (BFS (S, T) {del (cur, 0 ); int TM = DFS (S, INF, T); ans + = TM;} return ans;} void v_clear (int n) {for (INT I = 0; I <= N; I ++) V [I]. clear (); E. clear () ;}int main () {// freopen ("input.txt", "r", stdin); int t; scanf ("% d", & T ); for (int cas = 1; CAS <= T; CAS ++) {int n, m, sum = 0; scanf ("% d", & N, & M); int S = 0, T = N + m + 1, x; For (INT I = 1; I <= N; I ++) scanf ("% d", & X), add_node (S, I, x), sum + = x; For (INT I = 1; I <= m; I ++) scanf ("% d", & X), add_node (n + I, t, x); For (INT I = 1; I <= N; I ++) {scanf ("% d", & X); While (X --) {int TMP; scanf ("% d", & TMP); add_node (I, N + TMP + 1, INF) ;}}for (INT I = 1; I <= m; I ++) {for (Int J = 1; j <= m; j ++) {scanf ("% d", & X); If (x) add_node (n + I, n + J, INF );}} printf ("case # % d: % d \ n", Cas, Sum-dinci (S, T); v_clear (t) ;}return 0 ;}


Hdoj 4971 a simple brute force problem. [maximum closing weight --> Minimum Cut]

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.