bzoj3168 [Heoi2013] Calcium iron Zinc Selenium Vitamin __ Gauss elimination

Source: Internet
Author: User
Tags abs

Topic Link: bzoj3168
The main effect of the topic:
Kobayashi prepared 2 sets of Chef robot, a set of chef robot has N, each chef robot will only do a dish, this dish can provide the first I kind of nutrition XI micrograms. The 2nd set of chef Robots was used to make the 1th set of spares. Kobayashi needs to select a 2nd set of chef robots for every 1th set of cooks to make a backup, so that when the robot is broken, the whole chef robot can still match any nutritional needs, and Each 2nd set of Chef robots can only be a backup of the robot for a 1th set of cooks. If the task can not be completed, the output "NIE", otherwise the output "TAK", and followed by n rows, the I line represents the 1th set of robot backup is which 2nd set of robots. If there are many possible answers, please give the group with the smallest dictionary order.

Exercises
Inverse + binary graph matching of matrices
Look at the second half is to ask us to find the dictionary order the smallest complete matching scheme.
Then the first thing to solve is the matching problem.
I read the question for a long time, so much nonsense.
It is first known that any set of linearly independent vectors can be used as a substrate to represent any vector.
From the bold section above, the first set of robots is linearly independent, and if the 2nd set of robots can be replaced by a robot in the first set, then it is also required that the replacement robot group be linearly independent.
Reference to the ATP
We set a parameter matrix C C, the first applied a, and the second applies b b.
Because A is a linearly independent vector group, the vectors in each b b can be represented by a A.
That is, there is Bi=∑ni=1ciai b_i=\sum_{i=1}^nc_ia_i, that is B=cxa b=c\times a.
To see if the Bi b_i can replace Aj A_j, just look at the factor of not 0. Because if the coefficient is 0, which means that the remaining a a can still represent the Bi b_i, it does not satisfy the linear independent.
and request C C, only ask A−1 a^{-1}, both sides with a−1 a^{-1} on the good.
Then this is the use of Gauss elimination. Do not use double to remove the 0.

Eh all kinds of wrong + dictionary order when the random greedy seconds wa 4 hair.
Binary graph matching requires the minimum dictionary order can not be done again ah ... I thought it was like bzoj1562. From big to small is OK. The
should do this: do a complete match first, and then from 1 to N to the big greedy, see if you can find not affect the front of the staggered ring to change.

#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream
> #include <algorithm> using namespace std;
typedef long Long LL;
#define N 310 const LL mod=1e9+7;
const double eps=1e-5;
LL A[n][n],b[n][n],inv[n][n];int N;
BOOL Map[n][n];int Bf[n],gf[n],vis[n],tim;
    ll Qpow (ll X,int t) {ll ret=1;
        while (t) {if (t&1) ret= (ret*x)%mod;
    x= (x*x)%mod;t>>=1;
}return ret;
    } void Gauss () {for (int i=1;i<=n;i++) inv[i][i]=1;
        for (int i=1;i<=n;i++) {int now=i;
        for (int j=i+1;j<=n;j++) if (ABS (A[now][i]) <abs (a[j][i)) now=j;
                if (now!=i) {for (int j=1;j<=n;j++) {swap (a[now][j],a[i][j]);
            Swap (inv[now][j],inv[i][j]);
        } LL Tt=qpow (a[i][i],mod-2)%mod;
        Double Tt=1.0/a[i][i]; for (int j=1;j<=n;j++) {//AI
            [J]*=tt;inv[i][j]*=tt;
            A[i][j]=a[i][j]*tt%mod;
        Inv[i][j]=inv[i][j]*tt%mod; 
             for (int j=1;j<=n;j++) if (j!=i && abs (a[j][i)) >0) {//tt=a[j][i];
             Tt=a[j][i]%mod;
                 for (int k=1;k<=n;k++) {//A[j][k]-=a[i][k]*tt;
                Inv[j][k]-=inv[i][k]*tt;
                a[j][k]= (A[J][K]-A[I][K]*TT)%mod;
             inv[j][k]= (INV[J][K]-INV[I][K]*TT)%mod;
        }} void Get_c () {for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) {LL now=0;
         for (int k=1;k<=n;k++)//NOW+=B[I][K]*INV[K][J];
        now= (now+b[i][k]*inv[k][j]%mod)%mod;
        if (now) map[j][i]=true;
        if (Fabs (now) >eps) map[i][j]=true;
     else Map[j][i]=false; BOOL Ffind (int x) {for (int i=1;i<=n;i++) if (map[x][i) && vis[i]!=tim) {vis[i]=tIm
             if (Bf[i]==-1 | | ffind (bf[i])) {bf[i]=x;gf[x]=i;
         return true;
return false; BOOL Ffind2 (int x,int fr) {for (int i=1;i<=n;i++) if (map[x][i) && Vis[i]!=tim) {Vis
         [I]=tim;
             if (bf[i]==fr | | bf[i]>fr && ffind2 (BF[I],FR))//The BF[I]&GT;FR here is to ensure that it does not affect the previous only after the FR of {
             Bf[i]=x;gf[x]=i;
         return true;
return false;
    int main () {//freopen ("a.in", "R", stdin);
    Freopen ("A.out", "w", stdout);
    int I,j;bool flag=true;
    scanf ("%d", &n);
    for (i=1;i<=n;i++) for (j=1;j<=n;j++) scanf ("%lld", &a[i][j));
    for (i=1;i<=n;i++) for (j=1;j<=n;j++) scanf ("%lld", &b[i][j));
    Gauss (); Get_c ();
       for (i=1;i<=n;i++)//{/for (j=1;j<n;j++)//printf ("%d", map[i][j]);
    printf ("%d\n", Map[i][n]); } tim=0;memset (Bf,-1,sizeoF (BF));
        for (i=n;i>=1;i--) {tim++;
    if (!ffind (i)) {flag=false;break}
    } if (!flag) printf ("nie\n");
        else {printf ("tak\n");
            for (i=1;i<=n;i++) {tim++;
        Ffind2 (I,i);
    for (i=1;i<=n;i++) printf ("%d\n", Gf[i]);
return 0; }

Attach: Gauss elimination of the inverse of the matrix to find the method
Learning materials: ATP summary
What is called the inverse of the matrix.
Set a matrix A A to satisfy the

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.