# 【UTR #2】题目交流通道

### 限制与约定

130$1 \leq n \leq 4$$0\leq k\leq 5 2301 \leq n \leq 400$$0\leq k\leq 10^9$对于所有 $u\neq v$，有 $d(u,v)\geq 1$
340$1 \leq n \leq 400$$0 \leq k \leq 10^9$

### 分析1

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#define LL long long

using namespace std;

inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}

char c=nc();int b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

int wt,ss[19];
inline void print(int x){
if (x<0) x=-x,putchar('-');
if (!x) putchar(48); else {
for (wt=0;x;ss[++wt]=x%10,x/=10);
for (;wt;putchar(ss[wt]+48),wt--);}
}

int n,m,ans,a[410][410],b[410][410],c[10];

bool check()
{
for (int k=1;k<=n;k++)
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (i!=j && i!=k && j!=k)
if (b[i][k]+b[k][j]<b[i][j]) b[i][j]=b[i][k]+b[k][j];
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (b[i][j]!=a[i][j]) return false;
return true;
}

void dfs(int x)
{
if (x==n*(n-1)/2+1)
{
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (i==j) b[i][j]=0;else b[i][j]=-1;
int s=0;
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
if (b[i][j]==-1) b[i][j]=c[++s],b[j][i]=c[s];
if (check()) ans++;
return ;
}
for (int i=0;i<=m;i++)
c[x]=i,dfs(x+1);
}

int main()
{
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
ans=0;
dfs(1);
print(ans);puts("");
return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#define LL long long

using namespace std;

inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}

char c=nc();int b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
int wt,ss[19];
inline void print(LL x){
if (x<0) x=-x,putchar('-');
if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}
}

int n,m,a[410][410];
LL f[410][410];
const LL mo=998244353;

bool check(int x,int y)
{
for (int i=1;i<=n;i++)
if (i!=x && i!=y)
if (a[x][i]+a[i][y]==a[x][y]) return true;
return false;
}

int main()
{
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++)
{
if (check(i,j)) f[i][j]=(LL)(m-a[i][j]+1);
else f[i][j]=1LL;
}
LL ans=1;
for (int i=1;i<=n;i++)
for (int j=i+1;j<=n;j++)
ans=ans*f[i][j]%mo;
print(ans),puts("");
return 0;
}


### 分析3

posted @ 2017-04-25 09:51  Xiejiadong  阅读(86)  评论(0编辑  收藏
levels of contents