hdu4888 Redraw Beautiful Drawings 最大流+判环
2020-12-13 05:57
标签:des style blog http color java os io hdu4888 大意:n*m的矩阵,每个格子可以是0~k,给出各行的和和各列的和,求格子数字唯一方案,或判断无解或不唯一。 题解: 最大流,每行一个点,每列一个点,起点到每行的点连流量等于这行的和的边,每列的点连流量等于这列的和的边到终点,每行的点连到每列的点流量为K的点。所有行的和不等于所有列的和 或 最大流不等于所有行的和 则无解。有解的话再判有没有环,有环说明多解,可以dfs判环。 我这题卡了好久,判环的地方怒有问题,后来我看别人代码,只用从1~nr(行数)作为起始位置就能判完,也就是从行的节点开始,如果所有节点都开始一发的话会超时……我觉得再开点东西来记忆的话应该可以更快点,日后再说吧。 (我的网络流是n个点,下标1~n的ISAP+GAP+CUR,怕不怕) 代码: hdu4888 Redraw Beautiful Drawings 最大流+判环,搜素材,soscw.com hdu4888 Redraw Beautiful Drawings 最大流+判环 标签:des style blog http color java os io 原文地址:http://www.cnblogs.com/yuiffy/p/3891639.html
Redraw Beautiful Drawings
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2007 Accepted Submission(s): 447
Today Alice designs a game using these drawings in her memory. First, she matches K+1 colors appears in the picture to K+1 different integers(from 0 to K). After that, she slices the drawing into grids and there are N rows and M columns. Each grid has an integer on it(from 0 to K) representing the color on the corresponding position in the original drawing. Alice wants to share the wonderful drawings with Bob and she tells Bob the size of the drawing, the number of different colors, and the sum of integers on each row and each column. Bob has to redraw the drawing with Alice‘s information. Unfortunately, somtimes, the information Alice offers is wrong because of Alice‘s poor math. And sometimes, Bob can work out multiple different drawings using the information Alice provides. Bob gets confused and he needs your help. You have to tell Bob if Alice‘s information is right and if her information is right you should also tell Bob whether he can get a unique drawing.
For each testcase, the first line contains three integers N(1 ≤ N ≤ 400) , M(1 ≤ M ≤ 400) and K(1 ≤ K ≤ 40). N integers are given in the second line representing the sum of N rows. M integers are given in the third line representing the sum of M columns.
The input is terminated by EOF. 1 #include
文章标题:hdu4888 Redraw Beautiful Drawings 最大流+判环
文章链接:http://soscw.com/essay/32099.html