2014多校3(1002)hdu4888(最大流(dinic))
来源:互联网 发布:去掉数组中重复的元素 编辑:程序博客网 时间:2024/06/05 11:17
Redraw Beautiful Drawings
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2213 Accepted Submission(s): 495
Problem Description
Alice and Bob are playing together. Alice is crazy about art and she has visited many museums around the world. She has a good memory and she can remember all drawings she has seen.
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.
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.
Input
The input contains mutiple testcases.
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.
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.
Output
For each testcase, if there is no solution for Bob, output "Impossible" in one line(without the quotation mark); if there is only one solution for Bob, output "Unique" in one line(without the quotation mark) and output an N * M matrix in the following N lines representing Bob's unique solution; if there are many ways for Bob to redraw the drawing, output "Not Unique" in one line(without the quotation mark).
Sample Input
2 2 44 24 2 4 2 22 2 5 05 41 4 391 2 3 3
Sample Output
Not UniqueImpossibleUnique1 2 3 3
题意:给出一个矩阵,输入n,m代表矩阵的行和列,然后是n个数代表每行的数的总和,然后是m个数代表每列的总和
求:给矩阵每个位置填数,要求输入的每行和每列的总和都满足
思路:很容易想到网络流,重点在建图,首先从源点向每行的节点连边,流量为该行的总和,然后每行的节点向每列的节点连边,流量为K,最后是每列的节点向汇点连边,流
量为每列的总和,然后求最大流,满流就是有解,然后题目还要求在有解的情况下要判断是否有多解,这个只用在残留网络中用DFS找环即可,存在环则有多解,因为可以通过
环来改变各条边的流量,还有就是注意建图的时候要边输入边建图,不然就会TL,被这个坑了好久= =
0 0
- 2014多校3(1002)hdu4888(最大流(dinic))
- hdu4888 最大流,dinic模板
- hdu4888 最大流(构造矩阵)
- Redraw Beautiful Drawings(hdu4888)网络流+最大流
- 最大网络流(Dinic)
- 最大流模板(Dinic)
- 最大流(dinic) hdu3572
- Dinic算法(最大流)
- 最大流(Dinic临接表)
- 网络流hdu4888(多校联合)
- Dinic算法(网络流,最大流)
- 网络最大流(dinic)【模板】
- 最大流Dinic模版(LRJ)
- poj 1459 最大流(Dinic)
- 最大流模板(Dinic算法)
- 网络最大流(dinic)模板
- POJ 3281 Dining(最大流-Dinic)
- POJ 1149 PIGS(最大流-Dinic)
- PHP语法自动检查的Vim插件
- UVA524- Prime Ring Problem
- android编程:解决异常“android.view.InflateException: Binary XML file line # : Error inflating class”
- 剑指Offer29数组中出现次数超过一半的数字
- VC6 python 扩展
- 2014多校3(1002)hdu4888(最大流(dinic))
- bnu36907 Subpalindromes 字符串hash+线段树
- 《学生信息管理系统》又一些优化和系统总结
- PKU 2828 Buy Tickets 线段树想法题 (第4天)
- 【算法学习笔记】10.数据结构基础 二叉树初步练习3(遍历与递归复习)
- POJ 3600 Subimage Recognition【递归DFS + 模拟枚举】
- hdu 1573 X问题
- 【140812】半透明窗体效果的vc++12星座时钟源码
- mtd_utils 移植