题解 | Checkers-2019牛客暑期多校训练营第九场G题

题目来源于牛客竞赛:https://ac.nowcoder.com/acm/contest/discuss
题目描述:
题解 | Checkers-2019牛客暑期多校训练营第九场G题_第1张图片
输入描述:
题解 | Checkers-2019牛客暑期多校训练营第九场G题_第2张图片
输出描述:
在这里插入图片描述
示例1:
题解 | Checkers-2019牛客暑期多校训练营第九场G题_第3张图片
题解:
题解 | Checkers-2019牛客暑期多校训练营第九场G题_第4张图片
代码:

#include 
#include 
#include 
 
using namespace std;
using namespace __gnu_pbds;
  
#define fi first
#define se second
#define mp make_pair
#define pb push_back
  
typedef long long ll;
typedef pair ii;
typedef vector vi;
typedef unsigned long long ull;
typedef long double ld;
typedef tree, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
vector fact;
vector ifact;
vector inv;
vector pow2;
const int MOD = (1e9 + 7);
void radd(int &a, int b)
{
    a+=b;
    while(a>=MOD) a-=MOD;
}
 
int add(int a, int b)
{
    a+=b;
    while(a>=MOD) a-=MOD;
    return a;
}
int mult(int a, int b)
{
    return (a*1LL*b)%MOD;
}
int modpow(int a, int b)
{
    int r=1;
    while(b)
    {
        if(b&1) r=mult(r,a);
        a=mult(a,a);
        b>>=1;
    }
    return r;
}
int inverse(int a)
{
    return modpow(a,MOD-2);
}
void init(int _n)
{
    fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
    fact.resize(_n+1);
    ifact.resize(_n+1);
    inv.resize(_n+1);
    pow2.resize(_n+1);
    pow2[0]=1;
    ifact[0]=1;
    fact[0]=1;
    for(int i=1;i<=_n;i++)
    {
        pow2[i]=add(pow2[i-1],pow2[i-1]);
        fact[i]=mult(fact[i-1],i);
        //ifact[i]=mult(ifact[i-1],inv[i]);
    }
    ifact[_n] = inverse(fact[_n]);
    for(int i=_n-1;i>=1;i--)
    {
        ifact[i] = mult(ifact[i + 1], i + 1);
    }
    for(int i=1;i<=_n;i++)
    {
        inv[i] = mult(fact[i-1],ifact[i]);
    }
}
 
const int M = 12;
const int N = 155;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
const int C = 4;
 
struct DSU
{
    int S;
    struct node
    {
        int p;
    };
    vector dsu;
    DSU(int n)
    {
        S = n;
        for(int i = 0; i < n; i++)
        {
            node tmp;
            tmp.p = i;
            dsu.pb(tmp);
        }
    }
    int rt(int u)
    {
        if(dsu[u].p == u) return u;
        dsu[u].p = rt(dsu[u].p);
        return dsu[u].p;
    }
    void merge(int u, int v)
    {
        u = rt(u); v = rt(v);
        if(u == v) return ;
        if(rand()&1) swap(u,v);
        dsu[v].p = u;
    }
};
 
map ma;
vi F[555];
const int C2 = 76;
 
vi horizontal_connect(vi conn, int bit)
{
    vi nw(C,0);
    DSU dsu(C*2+3);
    assert(conn.size()==C);
    int cur=C+1;
    for(int i=0;i+10&&(dsu.rt(conn[i])==conn[i])&&ID[conn[i]]==-1)
        {
            ID[conn[i]]=c++;
        }
    }
    for(int i=0;i S; set S2;
    for(int i=0;i0) bit^=(1< vec)
{
    int n = vec.size();
    if(vec.empty()) return 0;
    set S;
    for(int i=0;i0&&S.find(mp(i,2*z+1))==S.end())
                                {
                                    pos=0; break;
                                }
                                if(bit&(1<0) //(i,2z) just became bad
                                {
                                    if(S.find(mp(i-1,2*z))!=S.end() && !(l&(1<0&&S.find(mp(i,2*z))==S.end())
                                {
                                    pos=0; break;
                                }
                                if(bit&(1<0) //(i+1,2z) just became bad, push to all 4 directions
                                {
                                    //up not needed
                                    if(S.find(mp(i+2,2*z))!=S.end())
                                    {
                                        cnt++;
                                    }
                                    //spread to left and right
                                    if(S.find(mp(i+1,2*z+1))!=S.end())
                                    {
                                        cnt++;
                                    }
                                    if(S.find(mp(i+1,2*z-1))!=S.end()&&nw[z-1]==0)
                                    {
                                        cnt++;
                                    }
                                }
                            }
                            radd(dp[i+1][bit][ma[nw]][g(k)], mult(v, inv[(1< vec)
{
    int n = vec.size();
    vector V[2];
    for(int i=0;i>n;
    vector vec;
    for(int i=0;i>x>>y;
        vec.pb(mp(x,y));
    }
    cout<

更多问题,更详细题解可关注牛客竞赛区,一个刷题、比赛、分享的社区。
传送门:https://ac.nowcoder.com/acm/contest/discuss

你可能感兴趣的:(题解,19牛客暑期多校训练营第九场)