Poj1698: http://poj.org/problem? Id = 1698
Alice wants to make a movie. There are n movies. It is required that Alice can make a movie every week for only a fixed number of days. She can only take the first W weeks, and the movie will take D days and ask Alice if she can finish all the movies.
Question: here is a bit of skill. At first I thought of putting every day together. In fact, to consider the time issue, we must differentiate every day in different weeks, in this way, creating a graph is correct.
1 # include <iostream> 2 # include <cstring> 3 # include <algorithm> 4 # include <cstdio> 5 # include <queue> 6 # define INF 100000000 7 using namespace STD; 8 const int n = 805; 9 const int M = 1000000; 10 struct node {11 int V; 12 int f; 13 int next; 14} edge [m]; 15 int n, m, U, V, CNT, Sx, ex; 16 int head [N], pre [N]; 17 int val1 [N], val2 [N]; // apply for 18 void Init () {19 CNT = 0; 20 memset (Head,-1, sizeof (head); 21} 22 as required Void add (int u, int V, int W) {23 edge [CNT]. V = V; 24 edge [CNT]. F = W; 25 edge [CNT]. next = head [u]; 26 head [u] = CNT ++; 27 edge [CNT]. f = 0; 28 edge [CNT]. V = u; 29 edge [CNT]. next = head [v]; 30 head [v] = CNT ++; 31} 32 bool BFS () {33 memset (PRE, 0, sizeof (pre )); 34 pre [SX] = 1; 35 queue <int> q; 36 Q. push (SX); 37 while (! Q. Empty () {38 int d = Q. Front (); 39 Q. Pop (); 40 for (INT I = head [d]; I! =-1; I = edge [I]. Next) {41 if (edge [I]. F &&! Pre [edge [I]. v]) {42 Pre [edge [I]. v] = pre [d] + 1; 43 Q. push (edge [I]. v); 44} 45} 46} 47 return pre [Ex]> 0; 48} 49 int dinic (INT flow, int PS) {50 int F = flow; 51 if (PS = ex) return F; 52 for (INT I = head [PS]; I! =-1; I = edge [I]. next) {53 If (edge [I]. F & Pre [edge [I]. v] = pre [PS] + 1) {54 int A = edge [I]. f; 55 int T = dinic (min (A, flow), edge [I]. v); 56 edge [I]. f-= T; 57 edge [I ^ 1]. F + = T; 58 flow-= T; 59 If (flow <= 0) break; 60} 61 62} 63 If (F-flow <= 0) pre [PS] =-1; 64 return F-flow; 65} 66 int solve () {67 int sum = 0; 68 while (BFS ()) 69 sum + = dinic (INF, SX); 70 return sum; 71} 72 int A [8]; 73 int main () {74 int T, K, temp, sum, tt = 0, T1, T2; 75 scanf ("% d", & T); 76 while (t --) {77 scanf ("% d", & N ); tt = 0; 78 Init (); sum = 0; SX = 0, Ex = 380; 79 for (INT I = 1; I <= N; I ++) {80 for (Int J = 1; j <= 7; j ++) {81 scanf ("% d", & A [J]); 82} 83 scanf ("% d", & T1, & T2); 84 sum + = T1; 85 for (Int J = 1; j <= 7; j ++) {86 if (a [J] = 1) {87 for (int K = 0; k <t2; k ++) 88 add (I + 350, K * 7 + J, 1); 89} 90} 91 add (0, I + 350, T1); 92} 93 for (INT I = 1; I <= 350; I ++) 94 add (I, sums, 1); 95 If (sum = solve () {96 printf ("Yes \ n "); 97} 98 else printf ("NO \ n"); 99 100 101} 102 return 0; 103}View code
Alice's chance