其他分享
首页 > 其他分享> > 【纪中集训】2019.08.01【NOIP提高组】模拟 A 组TJ

【纪中集训】2019.08.01【NOIP提高组】模拟 A 组TJ

作者:互联网

T1

Description


#include <bits/stdc++.h>
#define S(a) memset(a,0,sizeof a);
#define C(a,b) memcpy(a,b,sizeof a);
#define fo(i,a,b) for(i=a;i<=b;i++)
#define go int k,xx,yy; fo(k,0,3)if((xx=x+v[k][0])&&xx<=n&&(yy=y+v[k][1])&&yy<=n&&!vis[xx][yy])
using namespace std;

const int N=9,v[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int i,j,n,a[N][N],V[N][N],c[6],V2[6],deep;
bool vis[N][N];

void getV(int x,int y)
{
    vis[x][y]=V[x][y]=1;
    c[a[x][y]]--;
    go
    if(a[xx][yy]==a[x][y]) getV(xx,yy); else
    if(!V[xx][yy]) V[xx][yy]=2,V2[a[xx][yy]]++;
}

bool dfs(int t)
{
    int i,x,y,cs=0,pV[N][N],pc[6],pV2[6];
    fo(i,0,5) cs+=(bool)c[i];
    if(t+cs>deep) return 0;
    if(!cs) return 1;
    fo(i,0,5)
        if(V2[i])
        {
            C(pV,V) C(pc,c) C(pV2,V2)
            fo(x,1,n) fo(y,1,n) if(V[x][y]==2&&a[x][y]==i)
            {
                V2[a[x][y]]--;
                S(vis) getV(x,y);
            }
            if(dfs(t+1)) return 1; 
            C(V,pV) C(c,pc) C(V2,pV2)
        }
    return 0;
}

int main()
{
    for(scanf("%d",&n); n; scanf("%d",&n))
    {
        S(c)
        fo(i,1,n) fo(j,1,n) scanf("%d",&a[i][j]), c[a[i][j]]++;
        S(V) S(V2) S(vis) getV(1,1);
        fo(deep,0,n*n) 
        if(dfs(0)) break;
        printf("%d\n",deep);
    }
}

T2




#include <bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;

const int N=210;
int i,j,k,n,m,x,y,link[N],ans;
bool f[N][N],vis[N];

bool find(int x)
{
    if(vis[x]) return 0;
    vis[x]=1;
    int y;
    fo(y,1,n)
        if(f[x][y]&&(!link[y]||find(link[y])))
        {
            link[y]=x;
            return 1;   
        }
    return 0;
}

int main()
{
    scanf("%d%d",&n,&m);
    fo(i,1,m) scanf("%d%d",&x,&y), f[x][y]=1;
    fo(k,1,n) fo(i,1,n) fo(j,1,n) f[i][j]|=f[i][k]&f[k][j];
    fo(i,1,n)
    {
        fo(j,1,n) vis[j]=0;
        ans+=find(i);
    }
    printf("%d",n-ans);
}

T3

Description

#include <cstdio>
#include <cstring>
#define min(x,y) (x<y?x:y)
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;

const int mK=16,N=99,M=1e9+7;
int i,j,T,K,c,s,x,y;
ll C[N+1][N+1],f[mK][N];

int main()
{
    fo(i,0,N)
    {
        C[i][0]=1;
        fo(j,1,i) C[i][j]=(C[i-1][j-1]+C[i-1][j])%M;
    }
    for(scanf("%d",&T); T--;)
    {
        scanf("%d",&K);
        s=0, f[0][0]=1;
        fo(i,1,K)
        {
            memset(f[i],0,sizeof f[i]);
            scanf("%d",&c);
            fo(j,0,s)
                if(f[i-1][j])
                    fo(x,1,c)
                        fo(y,0,min(x,j))
                            (f[i][j-y+c-x]+=f[i-1][j]*C[s+1-j][x-y]%M*C[j][y]%M*C[c-1][x-1])%=M;
            s+=c;
        }
        printf("%lld\n",f[K][0]);
    }
}

标签:2019.08,01,define,最小链,纪中,V2,include,反链,fo
来源: https://www.cnblogs.com/Iking123/p/11284602.html