[八省联考2018]劈配

SOL:

  各种乱搞就好了。那个200的数据规模摆明了要送你分啦。

  

#include<bits/stdc++.h>
#define sight(c) (c>='0'&&c<='9')
#define gc getchar
#define Eho(x) for(int i=head[x];i;i=net[i])
#define v fall[i]
using namespace std;
void inline read(int &x){
    static char c;
    for(c=gc();!sight(c);c=gc());
    for(x=0;sight(c);x=x*10+c-48,c=gc());
}
#define N 407
#define M 80007
int S=403,t=404,be,ed,q[N],in[N],p[N][N],b[N],s[N],mer[N],usd[N];
struct Node{
    int head[N],fall[M],net[M],cost[M],tot,hea[N],x;
    inline void add(int x,int y,int co){
        fall[++tot]=y; net[tot]=head[x]; head[x]=tot; cost[tot]=co;
    } 
    inline void adds(int x,int y,int co) {
        add(x,y,co); add(y,x,0);
    }
    inline bool BFS() {
        memset(in,0,sizeof in);
        q[ed=be=1]=S; 
        while (be<=ed) {
            x=q[be++];
            Eho(x) if (cost[i]&&(!in[v])) in[v]=1,q[++ed]=v,mer[v]=i; 
        }
        return in[t];
    }
    inline void OUT() {
        for (int i=mer[t];;i=mer[i]) {
            cost[i]--; cost[i^1]++;
            i=fall[i^1];
            if (i==S) break;
        }
    }
}G;
void write(int x){if (x<10) {putchar('0'+x); return;} write(x/10); putchar('0'+x%10);}
inline void writeln(int x){ if (x<0) putchar('-'),x*=-1; write(x); putchar('
'); }
inline void writel(int x){ if (x<0) putchar('-'),x*=-1; write(x); putchar(' '); }
inline void clear() {
    memset(G.head,0,sizeof G.head);
    G.tot=1;
    memset(usd,0,sizeof usd);    
}
int T,C,n,m,ans1[N],pot[N],anw;
signed main () {
    read(T); read(C);
    while (T--) {
       clear(); 
       read(n); read(m); 
       for (int i=1;i<=m;i++) read(b[i]),G.adds(n+i,t,b[i]);
       for (int i=1;i<=m;i++) G.adds(S,n+i,0),pot[i]=G.tot-1;
       for (int i=1;i<=n;i++) 
        for (int j=1;j<=m;j++) read(p[i][j]);
       for (int i=1;i<=n;i++) read(s[i]);
       for (int i=1;i<=n;i++)  {
             G.adds(S,i,1); ans1[i]=m+1;
             for (int j=1;j<=m;j++) {
                 for (int k=1;k<=m;k++) if (!usd[k]&&p[i][k]==j) G.adds(i,k+n,1);
                 if(G.BFS()) 
                  {ans1[i]=j; G.OUT(); break;}      
         }
         for (int j=1;j<=m;j++) if (!usd[j]) {
             G.cost[pot[j]]=1;
             if (!G.BFS()) usd[j]=i;
             G.cost[pot[j]]=0;
         } 
       }
       for (int j=1;j<=n;j++) writel(ans1[j]); putchar(10);
       for (int j=1;j<=n;j++) {
            anw=0;
            for (int k=1;k<=m;k++) if (p[j][k]&&p[j][k]<=s[j]) {
            anw=max(anw,usd[k]); if (!usd[k]) anw=m+n+1; }
         writel(max(0,j-anw)); 
       } putchar(10);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/rrsb/p/8893705.html