ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25...
-
Upload
camden-leopard -
Category
Documents
-
view
222 -
download
0
Transcript of ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25...
![Page 1: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/1.jpg)
ACM so far…
Sep 11 Welcome! and DP problems ~ 6 problems
Sep 18 Lab session ~ 6 problems
Sep 25 Discussion session on graph problems ~ 6 problems
Oct 2 Lab session on graph problems ~ 6 problems
Oct 9 Scott Ellsworth on Google Irvine ~ 6 problems
Oct 16 Discussion session on maxflow problems ~ 6 problems
Oct 23 (9pm) Lab & local ACM qualifying contest ~ 6 problems
Oct 30 Discussion session on geometry problems ~ 6 problems
Nov 6 Lab session on geometry problems ~ 6 problems
Nov 10 (Sat.) ACM Regional contest (in Riverside...)
Nov 13 Final meeting
Job-fair thoughts?
![Page 2: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/2.jpg)
Our "sources"• Aaron Gable, Amber Yust, and other alums…
• Cory Simmonsen
Web technologies
Build systems
Distributed systems (scaling up)
Testing!
Working with a large existing codebase…
What should be improved?
![Page 3: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/3.jpg)
IT always seems mysterious to me…
Hooray!
Not sure about these, however…
![Page 4: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/4.jpg)
Matrix of skillsets
![Page 5: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/5.jpg)
Ford-Fulkerson algorithm
What's the maximum flow possible, from src to sink?
s
B
E
D
C13
t
16
10 4 9
12
14
7
20
4source
capacity
Max Flow !
sink or target
![Page 6: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/6.jpg)
s
B
E
D
C13
sB
C
D
E
FROM
s B C D E
t
- 16 13 - -- - 10 12 -
- 4 - - 14
- - 9 - -
- - - 7 -
--
-
20
4
- - - - - -t
t
16
10 4 9
12
14
7
20
4
TO
Capacity Graph
source
sink
(Step #1) Use depth- or breadth-first search to find any path from s to t.
Max Flow
What's left ?
![Page 7: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/7.jpg)
s
B
E
D
C13
sB
C
D
E
FROM
s B C D E
t
- 16 13 - -- - 10 12 -
- 4 - - 14
- - 9 - -
- - - 7 -
--
-
20
4
- - - - - -t
t
4/16
10 4 9
0/12
14
7
8/20
4
TO
Old capacities
source
sink
(Step #1) Use depth- or breadth-first search to find any path from s to t.
Max Flow
What's left… sB
C
D
E
FROM
s B C D E
- 4 13 - -12 - 10 0 -
- 4 - - 14
- 12 9 - -
- - - 7 -
--
-
8
4
- - - 12 - -t
t
TO
Residual capacities.
and the red edges?Backwards capacities!
12 12
12
![Page 8: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/8.jpg)
s
B
E
D
C13
sB
C
D
E
FROM
s B C D E
t
- 16 13 - -- - 10 12 -
- 4 - - 14
- - 9 - -
- - - 7 -
--
-
20
4
- - - - - -t
t
4
10 4 9
0
14
7
8
4
TO
source
sink
(Step #1) Use depth- or breadth-first search to find any path from s to t.
Max Flow
sB
C
D
E
FROM
s B C D E
- 4 13 - -12 - 10 0 -
- 4 - - 14
- 12 9 - -
- - - 7 -
--
-
8
4
- - - 12 - -t
t
TO
12 12
12
(Step #2) Continue with the remaining capacities until no path exists!
Old capacities
Residual capacities.
Backwards capacities.
New capacities
![Page 9: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/9.jpg)
B
E
D
C12/13
11/16
0/10 1/4 0/9
12/12
11/14
7/7
19/20
4/4
max flow: 23
(Step #1) Use depth- or breadth-first search to find any path from s to t.
Max Flow
(Step #2) Continue with the remaining capacities until no path exists!
ssource
t
sink
![Page 10: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/10.jpg)
Setting up…
if __name__ == "__main__":
# make a capacity graph # node A B C D E F C = [ [ 00, 16, 13, 00, 00, 00 ], # A [ 00, 00, 10, 12, 00, 00 ], # B [ 00, 04, 00, 00, 14, 00 ], # C [ 00, 00, 9, 00, 00, 20 ], # D [ 00, 00, 00, 7, 00, 4 ], # E [ 00, 00, 00, 00, 00, 00 ] ] # F
print "C is", C source = 0 # A sink = 5 # F
max_flow_value = max_flow( C, source, sink ) print "max_flow_value is", max_flow_value
And the code needed to run it…
Linked at the ACM website by the slides…
![Page 11: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/11.jpg)
Get into the flow!
def max_flow(C, source, sink): n = len(C) # C is the capacity matrix F = [[0] * n for i in range(n)] # F is the flow matrix # residual capacity from u to v is C[u][v] - F[u][v]
while True: path = BFS(C, F, source, sink) if not path: break # no path - we're done!
# find the path's flow, that is, the "bottleneck" edges = [C[u][v]-F[u][v] for u,v in path] path_flow = min( edges ) print "Augmenting by", path_flow for u,v in path: # traverse path to update flow F[u][v] += path_flow # forward edge up F[v][u] -= path_flow # backward edge down
return sum([F[source][i] for i in range(n)]) # out from source
A little bit of name contention…
edmonds_karpThis is the algorithm.
![Page 12: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/12.jpg)
Useful alone, too
def BFS(C, F, source, sink): queue = [source] # the BFS queue paths = {source: []} # stores 1 path per graph node while queue:
u = queue.pop(0) # next node to explore (expand) for v in range(len(C)): # for each possible next node
# path from u to v? and not yet at v? if C[u][v] - F[u][v] > 0 and v not in paths: paths[v] = paths[u] + [(u,v)] if v == sink: return paths[v]
queue.append(v) # go from v in the future return None
A brief BFS algorithm using the Capacity matrix
![Page 13: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/13.jpg)
But is max flow good for anything?
that is, beyond solving "max flow" problems...
![Page 14: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/14.jpg)
we have four brides and six grooms
Matching! and some acceptable possibilities ...
a bipartite graph
![Page 15: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/15.jpg)
we have four brides and six grooms
Matching! and some acceptable possibilities ...
a maximal matching == no more matchings without rearrangement
![Page 16: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/16.jpg)
we have four brides and six grooms
Matching! and some acceptable possibilities ...
a maximum matching == no rearrangements will yield more matchings
![Page 17: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/17.jpg)
Maximum matching is max flow...
ssource
connect a source to the left side...
all 1s
![Page 18: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/18.jpg)
Maximum matching is max flow...
ssource
connect a source to the left side...
make all capacities = 1
1
1
11
1
1
all 1s
![Page 19: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/19.jpg)
Maximum matching is max flow...
ssource
t
sink
connect a source to the left side...
put a sink on the right
make all capacities = 1
1
1
11
1
1
all 1sall 1s
what do the source and sink constraints ensure?
![Page 20: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/20.jpg)
Max flow thought experiment...
ssource
t
sink
1
1
11
1
1
all 1sall 1s
Suppose this is the flow so far (3 units):
Draw what happens in the next step of the max-flow algorithm!how to get from maximal matching to maximum matching…
![Page 21: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/21.jpg)
Max flow thought experiment...
ssource
t
sink
1
1
11
1
1
all 1sall 1s
... the path it finds ...
What's going on here?
![Page 22: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/22.jpg)
Max flow thought experiment...
ssource
t
sink
1
1
11
1
1
all 1sall 1s
Done!
Maximum matching == 4
![Page 23: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/23.jpg)
general problems: max-flow problems:
cowcarn
feeding
optimilk
sandcastimecards
tswift
difficult-to-classify problems:
This week's problemsTry max flow!
soda (last week)tour (last week)
![Page 24: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/24.jpg)
The challenge:
is sometimes setting up the graph
![Page 25: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/25.jpg)
4 44218910100050 1 320 1 3 8 2 3 1 4
How do we use the results?
What is flowing?
tswiftThere are four ingredients available ~ at these costs
hay-flavored
coffee
spam
chocolate
There are four smoothie recipes available ~ with these rewards
4 ingredients (hay) & 4 smoothie recipes
each recipe requires ingredients
1
2
3
4
![Page 26: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/26.jpg)
4 44218910100050 1 320 1 3 8 2 3 1 4
source
42
189
10
1000ingredient
costs
How do we use the results?
What is flowing?
tswiftThere are four ingredients available ~ at these costs
hay-flavored
coffee
spam
chocolate
There are four smoothie recipes available ~ with these rewards
Hay
coffee
Spam
Choc.
4 ingredients (hay) & 4 smoothie recipes
each recipe requires ingredients
1
2
3
4ingredients
![Page 27: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/27.jpg)
4 44218910100050 1 320 1 3 8 2 3 1 4
sourcesink
42
189
10
1000ingredient
costs
recipe rewards
50
20
8
3
How do we use the results?
What is flowing?
tswiftThere are four ingredients available ~ at these costs
hay-flavored
coffee
spam
chocolate
There are four smoothie recipes available ~ with these rewards
Hay
coffee
Spam
Choc.
4 ingredients (hay) & 4 smoothie recipes
each recipe requires ingredients
Hay-spam
Spam-hay
coffee
Choco-hay
1
2
3
4ingredients recipes
![Page 28: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/28.jpg)
4 44218910100050 1 320 1 3 8 2 3 1 4
sourcesink
42
189
10
1000ingredient
costs
recipe rewards
50
20
8
3
How do we use the results?
What is flowing?
tswiftThere are four ingredients available ~ at these costs
hay-flavored
coffee
spam
chocolate
There are four smoothie recipes available ~ with these rewards
Hay
coffee
Spam
Choc.
4 ingredients (hay) & 4 smoothie recipes
each recipe requires ingredients
Hay-spam
Spam-hay
coffee
Choco-hay
1
2
3
4
One purple edge is missing… Which?
ingredients recipes
What should these capacities be?
![Page 29: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/29.jpg)
general problems: max-flow problems:
cowcarn
feeding
optimilk
sandcastimecards
tswift
difficult-to-classify problems:
This week's problemsTry max flow!
soda (last week)tour (last week)
![Page 30: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/30.jpg)
This code only looks
obfuscated!
![Page 31: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/31.jpg)
Donut!
http://www.ioccc.org/
donut.c
International Obfuscated C Coding Contest
This code
IS
obfuscated!
![Page 32: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/32.jpg)
2011's winner…
http://www.ioccc.org/
donut.c
International Obfuscated C Coding Contest
This code
IS
obfuscated!
![Page 33: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/33.jpg)
Tools
4 44218910100050 1 320 1 3 8 2 3 1 4
source
Jobs
sink
42
189
10
1000tool costs
task rewards
50
20
8
3
How do we use the results?
What is flowing?
hardwareThere are four tools available ~ at these costs
hammer
TV
coffee
PC
There are four tasks available ~ with these rewards
hammer
TV
coffee
PC
4 tools & 4 tasks
each task requires some tools
E4
waking folks in
east
sleep
coding
![Page 34: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/34.jpg)
dinner
4 54 5 3 53 5 2 6 44 54 5 3 53 5 2 6 30 0
number of teams Input
Output
number of tables
# of people in each team
can an assignment be made without putting teammates together?
01
capacity of each table
again…
end…
35
2 6 4
tables with capacities
teams with sizes
5
34
5
seating assignments!
no teammates
![Page 35: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/35.jpg)
dinner's maxflow graph
ssource t
sink
How does the maxflow here relate to whether the seating is possible or not?
Team
Team
Team
Team
Table
Table
Table
Table
Table
4
3
6
5
2
5
5
3
4
fully connected with edge
weights of 1
How do these edge weights reflect the problem constraints?
![Page 36: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/36.jpg)
JRs SRs Elderly
slate 3
This term's first class to guess another's word earns 1 problem...
slate 2 slate 1
This term's last class to have its word guessed earns 1 problem...
Sophs
slate 1
flair 0 flair 1 flair 2 flair 0
Pomona
slate 3
flair 2
stems 3 stems 1 stems 2 stems 1 stems 2
loser 2 loser 3 loser 2loser 1 loser 3
stone 3 stone 2 stone 1 stone 1 stone 2
guppy 1 guppy 0 guppy 1 guppy 2 guppy 0
Try max flow!
lasso 1 lasso 3 lasso 1 lasso 1 lasso 2
pluot 1 pluot 2 pluot 1 pluot 1 pluot 0
![Page 37: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/37.jpg)
old years…
![Page 38: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/38.jpg)
hardware
Tools
4 44218910100050 1 320 1 3 8 0 3 1 4
source
Jobs
sink
42
189
10
1000
tool costs
job rewards
50
20
8
3
How can max flow help us here?
What is flowing?
![Page 39: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/39.jpg)
hardware
Tools
4 44218910100050 1 320 1 3 8 0 3 1 4
source
Jobs
sink
42
189
10
1000
tool costs
job rewards
50
20
8
3
How can max flow help us here?
What is flowing?
![Page 40: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/40.jpg)
4 3 32 2 1 2 3 12 2 2 3 1 22 2 1 3 1 22 1 1 3 3
number of cows
Inputtotal # of foods
total # of drinks
# of foods cow[i] likes
# of drinks cow[i] likesfoods drinks
0
Output
# of cows that can receive both a food and
a drink they like…
3
each can be used only once
Likes
foods drinks
1
2
3
1 2
2 3
1 3
1 3
3 1
1 2
1 2
3What is a cow-satisfying assignment here?
dining
![Page 41: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/41.jpg)
Jotto! Sophs Jrs Srs
audio 1 audio 2 audio 1
Frosh
audio 2 graze 3 graze 1 graze 1 graze 2
alloy 1 alloy 1 alloy 1 alloy 2 fresh 2 fresh 2 fresh 2 fresh 1
This term's first class to guess another's word earns 1 problem...
This term's last class to have its word guessed earns 1 problem...
armor 2 armor 2 armor 1 armor 2 brave 3 brave 1 brave 1 brave 2 wreak 3 wreak 1 wreak 2 wreak 2 fjord 1 fjord 5 fjord 1 fjord 2
![Page 42: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/42.jpg)
Stake
4 1 0 1 1 0 1 0 0 0 0 0 1 0 1 0 1
Input
Output3
Height and width of the field
the
patt
ern
Maximum number of cows such that no two share a column and no two share a row.
![Page 43: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/43.jpg)
Tools
4 44218910100050 1 320 1 3 8 2 3 1 4
source
Jobs
sink
50
20
8
3task rewards
tool costs
42
189
10
1000
How do we use mf to maximize our profit?
What is flowing?
hardwareThere are four tools available ~ at these costs
hammer
TV
coffee
PC
There are four tasks available ~ with these rewards
hammer
TV
coffee
PC
4 tools & 4 tasks
each task requires some tools
E4
waking folks in
east
sleep
coding
![Page 44: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/44.jpg)
Stake as matchingwho are the brides? and the grooms?
and the constraints?
![Page 45: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/45.jpg)
This week's problems…
Try one or more of this week's problems!
this one is from last week... ?
![Page 46: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/46.jpg)
Dijkstra, for single-source shortest paths
Put <S,0> into your queue Q.
While Q not empty:
Remove Q's nearest node <nc,dc>
For each edge [nc, nk, dc2k]:
For all nk , track <nk, Inf>
Let dk be nk's distance: <nk,dk>
If dc + dc2k < dk: set dk = dc + dc2k
Put <nk,dk> into Q...
S
shortest dist from S
![Page 47: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/47.jpg)
Dijkstra, for single-source shortest paths
Put <S,0> into your queue Q.
While Q not empty:
Remove Q's nearest node <nc,dc>
For each edge [nc, nk, dc2k]:
For all nk , track <nk, Inf>
Let dk be nk's distance: <nk,dk>
If dc + dc2k < dk: set dk = dc + dc2k
Put <nk,dk> into Q...
S
shortest dist from S
![Page 48: ACM so far… Sep 11 Welcome! and DP problems ~ 6 problems Sep 18 Lab session ~ 6 problems Sep 25 Discussion session on graph problems ~ 6 problems Oct 2.](https://reader035.fdocuments.us/reader035/viewer/2022062322/56649ca35503460f949628db/html5/thumbnails/48.jpg)
Jotto! Sophs Jrs Srs
audio 1 audio 2 audio 1
Frosh
audio 2 graze 3 graze 1 graze 1 graze 2
alloy 1 alloy 1 alloy 1 alloy 2 fresh 2 fresh 2 fresh 2 fresh 1
This term's first class to guess another's word earns 1 problem...
This term's last class to have its word guessed earns 1 problem...
armor 2 armor 2 armor 1 armor 2 brave 3 brave 1 brave 1 brave 2 wreak 3 wreak 1 wreak 2 wreak 2 fjord 1 fjord 5 fjord 1 fjord 2 taper 4 taper 1 taper 1 taper 2 tater 4 tater 1 tater 1 tater 2