# 牛客CSP-S提高组赛前集训营5 赛后总结

## A.无形的博弈

#include<bits/stdc++.h>
#define LL long long
const LL Mod=998244353;
int n;

int main()
{
scanf("%d",&n);
LL Ans=1;
for(int i=1;i<=n;i++)
Ans=(Ans<<1)%Mod;
printf("%lld",Ans);
return 0;
}


## B.十二桥问题

#include<bits/stdc++.h>
#define LL long long
const int N_MAX=50005,M_MAX=400005,SIZE=25+1;
{
}

struct Line
{
int A,B;
LL D;
}L[SIZE];
LL D[SIZE][SIZE];
int Raw[SIZE],F[N_MAX],Cnt;
void new_node(int x)
{
if(F[x])return;
Raw[++Cnt]=x;
F[x]=Cnt;
}

LL Dx[N_MAX];
bool mk[N_MAX];
struct node
{
int pos;
LL D;
bool operator <(const node &x)const
{
return D>x.D;
}
};
std::priority_queue<node>q;
void Dij(int S)
{
memset(Dx,0x3F,sizeof(Dx));
memset(mk,0,sizeof(mk));
Dx[S]=0;
q.push((node){S,Dx[S]});
while(q.size())
{
int u=q.top().pos;
q.pop();
if(mk[u])continue;
mk[u]=1;
{
int v=to[i];
if(Dx[v]>Dx[u]+edge[i])
{
Dx[v]=Dx[u]+edge[i];
q.push((node){v,Dx[v]});
}
}
}
}

LL DP[SIZE][1<<13];

int main()
{
scanf("%d%d%d",&n,&m,&k);
int u,v,e;
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&u,&v,&e);
if(i<=k)
{
new_node(u);
new_node(v);
L[i]=(Line){F[u],F[v],e};
}
}
new_node(1);
for(int i=1;i<=Cnt;i++)
{
Dij(Raw[i]);
for(int k=1;k<=Cnt;k++)
D[i][k]=Dx[Raw[k]];
}
memset(DP,0x3F,sizeof(DP));
DP[F[1]][0]=0;
for(int Statu=0;Statu<(1<<k);Statu++)
{
for(int i=1;i<=Cnt;i++)
{
for(int p=1;p<=k;p++)
{
for(int q=1;q<=Cnt;q++)
{
DP[i][Statu|(1<<(p-1))]=std::min(DP[i][Statu|(1<<(p-1))],DP[q][Statu]+D[q][L[p].A]+L[p].D+D[L[p].B][i]);
DP[i][Statu|(1<<(p-1))]=std::min(DP[i][Statu|(1<<(p-1))],DP[q][Statu]+D[q][L[p].B]+L[p].D+D[L[p].A][i]);
}
}
}
}
printf("%lld",DP[F[1]][(1<<k)-1]);
return 0;
}


## 神J上树

posted @ 2019-11-08 10:01  TaylorSwift13  阅读(194)  评论(0编辑  收藏  举报