"BZOJ3168" [Heoi2013] calcium fe zinc Selenium Vitamin Description Galaxy squad player list come out! Kobayashi, as a distinguished dietitian, will be responsible for the Galactic team to participate in the Universe game diet. As we all know, to a planet in the universe, usually take a long time, the body of the situation in the change between this, so the need to match the daily food, to ensure nutrition. Kobayashi divides the nutrients needed by the human body into N species, including but not limited to iron and calcium. He prepared 2 sets of Chef robot, a set of chef robot has N, each chef robot will only cook one dish, this dish can provide the first nutrition XI micrograms. When you want to eat this dish, just enter a number and you will be able to eat the corresponding amount of this dish. To prevent excessive body damage, each robot also has an anti-overdose drug, as long as the input of a number, you can generate a certain dose of medicine, eat these drugs, you can reduce the equivalent of the corresponding number of this dish to provide nutrition. Kobayashi prepared 2 sets of chef robot, it is because of the long journey, it is difficult to predict, perhaps a chef robot on the way to break down, if the impact of the Galaxy team player's body, it is not good. Therefore, the 2nd set of chef Robots was used to make the 1th set of spare. Kobayashi needs to select a 2nd chef robot for each 1th set of chefs to make a backup, so that when the robot breaks down and replaces it with a backup, the entire chef robot can still match any nutritional needs, and each 2nd set of chef bots can only be used as a backup of the 1th set of chef bots. The first line of input contains a positive integer n. The next n lines, n integers per line, represent the 1th set of cooks that the robot does every pound of food provided by each of the nutrients. Then the next n rows, n integers per line, represent the 2nd set of cooks the robot does every pound of the food provided by each of the nutrients. 1≤n≤300, all occurrences of the integer are non-negative and no more than 10,000. The first line of output is a string, if the task cannot be completed, output "NIE", otherwise output "TAK" and followed by n lines, line I is the 1th set of the robot's backup is which 2nd set of robots. To avoid trouble, if there are multiple possible answers, give the group with the smallest dictionary order. Sample Input3
1 0 0
0 1 0
0 0 1
2 3 0
0 7 8
0 0 9Sample OutputTAK
1
2
3
The puzzle: If you don't have a big uncle's work, I really don't necessarily understand test instructions ...
The question is: given an∗n The full rank matrixAand an∗n The MatrixB, ask for the smallest dictionary order1 ...n The arrangementaMeet any one of theAi Intob a i Post matrix A is still full rank.
Is it much clearer? This arrangement actually takes a by the last matrix C to make the ca=b,c=ab-1.
To find out C, we change the way of thinking, will use the edge i->j means that the B robot can replace a in the I-robot, and then get a binary map, and the CT is just the adjacency matrix of the binary graph, we want to find the best dictionary order of the binary map of the smallest perfect match.
At first think ye do trouble, straight from the back to do the Hungarian algorithm on the line, know I saw discuss ... OK or do both sides, the first time normal run, the second time the greedy selection of small, and the demand behind the point can not affect the front point.
Here is still to do the blog comments:
1. Why ca=b instead of ac=b??? (I don't understand it at first)
Because each robot corresponds to a row vector, and we want the row vectors in a to correspond to the other line vectors in B, it is obvious that the direct moment multiplication is not possible, but if we transpose a a A, a column vector in a will correspond to the other column vector in B, and then the atc= BT (where C refers to the adjacency matrix of a binary graph), equivalent to Cta=b
2. Does not affect the front of the staggered ring is what ghost? (Or do you think what I'm saying is not so clear?) )
Directly say the way: In the second time DFS to record the current is from that point to find the augmented road, it means that the number is smaller than this point of the point we can not affect. So let's take a look at the number of the robot in B that corresponds to a, if the number < start point, it cannot be changed, if the number = Start point, and we have to let the starting point and other points match, the point has been idle out, you can change, if the number > Start point, Then we'll just keep looking for the augmented path.
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #define MoD 999911657using namespace Std;const Double eps=1e-6;typedef long long ll;int n,ans;ll a[310][610],b[310][310],c[310][310 ];int vis[310],from[310],to[310];ll pm (ll X,ll y) {ll z=1;while (y) {if (y&1) z=z*x%mod;x=x*x%mod,y>>=1;} return z;} Int Rd () {int Ret=0;char gc=getchar (); while (gc< ' 0 ' | | Gc> ' 9 ') Gc=getchar (); while (gc>= ' 0 ' &&gc<= ' 9 ') ret=ret*10+gc-' 0 ', Gc=getchar (); return ret;} int DFS1 (int x) {for (int i=1;i<=n;i++) {if (C[i][x]&&!vis[i]) {vis[i]=1;if (!from[i]| | DFS1 (From[i]) {To[x]=i,from[i]=x;return 1;}}} return 0;} int dfs2 (int x,int y) {for (int i=1;i<=n;i++) {if (C[i][x]&&!vis[i]) {vis[i]=1;if (from[i]==y| | (FROM[I]>Y&&DFS2 (from[i],y))) {From[i]=x,to[x]=i;return 1;}}} return 0;} int main () {n=rd (); int i,j,k;for (i=1;i<=n;i++) for (j=1;j<=n;j++) a[i][j]=rd (), a[i][j+n]= (I==J); for (i=1;i<= n;i++) for (j=1;j<=n;j++) b[i][j]=rd (); ll T;for (i=1;i<=n;i++) {for (j=i;j<=n;j++) if (A[j][i]) {for (k=1;k<=2*n;k++) swap (a[i][k],a[j][k]); T=PM (a[i][i],mod-2); for (k=i;k<=2*n;k++) a[i][k]=a[i][k]*t%mod;for (j=1;j<=n;j++) if (i!=j) {t=A[j][i];for (k=1 ; k<=2*n;k++) a[j][k]= (A[j][k]-t*a[i][k]%mod+mod)%mod;}} for (i=1;i<=n;i++) for (j=1;j<=n;j++) for (k=1;k<=n;k++) c[i][j]= (C[i][j]+b[i][k]*a[k][j+n])%mod;for (i=1;i <=n;i++) {memset (vis,0,sizeof (Vis)); ans+=dfs1 (i);} if (ans<n) {printf ("NIE"); return 0;} printf ("tak\n"); for (i=1;i<=n;i++) {memset (vis,0,sizeof (VIS));d fs2 (i,i);} for (i=1;i<=n;i++) printf ("%d\n", To[i]); return 0;}
"BZOJ3168" [Heoi2013] the inverse + Hungarian algorithm of calcium fe-Zn-se vitamin Gaussian elimination matrix