「POJ2396」Budget

2014年6月3日4,0911

Description

We are supposed to make a budget proposal for this multi-site competition. The budget proposal is a matrix where the rows represent different kinds of expenses and the columns represent different sites. We had a meeting about this, some time ago where we discussed the sums over different kinds of expenses and sums over different sites. There was also some talk about special constraints: someone mentioned that Computer Center would need at least 2000K Rials for food and someone from Sharif Authorities argued they wouldn’t use more than 30000K Rials for T-shirts. Anyway, we are sure there was more; we will go and try to find some notes from that meeting.And, by the way, no one really reads budget proposals anyway, so we’ll just have to make sure that it sums up properly and meets all constraints.

Input

The first line of the input contains an integer N, giving the number of test cases. The next line is empty, then, test cases follow: The first line of each test case contains two integers, m and n, giving the number of rows and columns (m <= 200, n <= 20). The second line contains m integers, giving the row sums of the matrix. The third line contains n integers, giving the column sums of the matrix. The fourth line contains an integer c (c < 1000) giving the number of constraints. The next c lines contain the constraints. There is an empty line after each test case.Each constraint consists of two integers r and q, specifying some entry (or entries) in the matrix (the upper left corner is 1 1 and 0 is interpreted as “ALL”, i.e. 4 0 means all entries on the fourth row and 0 0 means the entire matrix), one element from the set {<, =, >} and one integer v, with the obvious interpretation. For instance, the constraint 1 2 > 5 means that the cell in the 1st row and 2nd column must have an entry strictly greater than 5, and the constraint 4 0 = 3 means that all elements in the fourth row should be equal to 3.

Output

For each case output a matrix of non-negative integers meeting the above constraints or the string “IMPOSSIBLE” if no legal solution exists. Put one empty line between matrices.

Sample Input

Sample Output

题解

真是坑爹题,搞了半个晚上。。。

首先建图不难

每一行的和为x,S到每行连[x,x]的边

每一列的和为y,每列到T连[y,y]的边

对于一个点i,j,i行向j列连[l,r]的边

然后正常的有源上下界网络流

还要处理输入自身的矛盾

注意初始化,并且l和r初始为+-1000即可,否则可能爆long long

注意输入是>和<,不能理解为>=和<=

注意数组大小

注意测试数据有负数

注意读完数据,不能读入过程中发现矛盾就退出了,有人说似乎读入每组数据最后要读入一个空行

此题不会卡常数,tle就是写错了

 

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
yangyh408 Recent comment authors
  Subscribe  
提醒
yangyh408

这道题报道上出现了偏差,zoj上wa了