首页 技术 正文
技术 2022年11月14日
0 收藏 687 点赞 3,497 浏览 1202 个字

链接接接接接!

正解:最短路+小学奥数 乘法原理

解题报告:

首先读懂题意(,,,我觉得我吃枣死于语文太差读不懂题目QAQ

大意就是港,要求从第一个点到其他各点的长度都是最短的方案有多少个(ummm,,,不知道表述清楚辽没有QAQ

那理解了大意就简单辣,不就是个小学奥数乘法原理嘛,然后剩下的实现过程和原理我昨儿写了一下直接贴过来辽

先跑一遍最短路,得到到每个点的dis
然后一个个点地看,看从它的邻点到它是最短路的有几个,然后ans*=个数
理解一下?
因为我有这么多个点过来,我就可以任取他们中的一条边留下其他的删了,然后根据小学奥数知识可以得到这相当于是分阶段那当然是乘法原理咯,乘一下就出来了
over

#include<bits/stdc++.h>#define N 57#define M 2507#define mod 1000000007#define ll long long#define inf 1000000007#define P pair<ll,ll>#define rp(i,x,y) for(register ll i=x;i<=y;++i)#define mp make_pairusing namespace std;ll n,head[N],dis[N],tot;struct ed{ll to,next,wei;}edge[M];bool vis[N];priority_queue< P,vector< P >,greater< P > >Q;inline ll read(){    ;;    '))ch=getchar();    ;    )+(x<<)+(ch^'),ch=getchar();    return y?x:-x;}inline void add(ll x,ll y,ll z){edge[++tot].to=x;edge[tot].next=head[y];edge[tot].wei=z;head[y]=tot;}inline void dij(){    memset(dis,/,,));vis[]=;dis[]=;    while(!Q.empty())    {        ll t=Q.top().second;Q.pop();        ;i=edge[i].next)            if(dis[edge[i].to]>dis[t]+edge[i].wei)            {                dis[edge[i].to]=dis[t]+edge[i].wei;                ;            }    }}int main(){    n=read();    rp(i,,n)        rp(j,,n){');}    dij();    ll ans=;    ;i<=n;i++)    {        ll tott=;        ;j=edge[j].next)        {            int t1=edge[j].to,t2=edge[j].wei;            if (dis[i]==dis[t1]+t2) tott++;        }        ans=(ans*tott)%mod;    }    printf("%lld",ans);}

哭辽?为什么我的代码这么丑别的大佬代码那么帅啊QAQ

这个还是,比较新手村的?overrrr

完美结束yeah

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,496
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,909
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,743
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,496
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,134
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298