A. Anadi and Domino (Thinking+dfs)

https://codeforces.com/problemset/problem/1210/A


Idea: n is only 7, violent search.

Thinking of building a violent search, but it will cause disconnection and it is a bit difficult to deal with.

So directly arrange all points (7!) for all points, and then check once when they are full.

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=8;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
vector<pair<LL,LL>>g;
LL p[maxn][maxn];
LL face[maxn];
LL ans=0;
LL res=0;
void update(LL n){
     memset(p,0,sizeof(p));
     for(LL i=0;i<g.size();i++){
         LL u=face[g[i].first];
         LL v=face[g[i].second];
         if(u>v) swap(u,v);
         if(!p[u][v]){
            p[u][v]=1;
            res++;
         }
     }
     ans=max(ans,res);
}
void dfs(LL u,LL n){
    if(u==n+1){
        res=0;
        update(n);
        return;
    }
    for(LL i=1;i<=6;i++){
        face[u]=i;
        dfs(u+1,n);
    }
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,m;cin>>n>>m;
  for(LL i=1;i<=m;i++){
    LL u,v;cin>>u>>v;
    g.push_back({min(u,v),max(u,v)});
  }
  dfs(1,n);
  cout<<ans<<"\n";
return 0;
}

 

Guess you like

Origin blog.csdn.net/zstuyyyyccccbbbb/article/details/114980460