【NOIP模拟赛19.8.26】死宅与陷阱

题目

在这里插入图片描述

思路

考场想用dijkstra求最短路得方法算出最大概率,但是错了:因为如果有两条路可以到达该点,那么到达这个点的概率应该是走这两条路的概率之和,而不是选择概率大的一条路。所以T1只有5分qwq

正解

直接暴力dfs算概率,最后把概率排序增加陷阱

代码

#include <bits/stdc++.h>
using namespace std;
#define N 100005
#define db double

int n,m,p,s,t,tot;
int v[N],head[N],to[N],Next[N],du[N];
db val[N],d[N],ans;
bool vis[N];

inline int read(){
	int x=0,f=0; char ch=getchar();
    while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
    while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
inline void add(int x,int y,db z){
	to[++tot] = y;
	val[tot] = z;
	Next[tot] = head[x];
	head[x] = tot;
	++du[y];
}
inline void Dfs(int x,db last){
	if(x != s) d[x] += last;
	ans += (v[x]*last);
	for(int i=head[x]; i; i=Next[i]){
		int y = to[i];
		double z = val[i];
		Dfs(y,last*z);
	}
}
int main()
{
//	freopen("trap.in","r",stdin);
//	freopen("trap.out","w",stdout);
	n=read(); m=read(); p=read(); s=read(); t=read();
	for(int i=1; i<=n; i++)
		v[i] = read();
	for(int i=1,ai,bi; i<=m; i++){
		db ci;
		ai=read();bi=read();scanf("%lf",&ci);
		add(ai,bi,ci);
	}
	Dfs(s,1);
	sort(d+1,d+1+n);
	for(int i=n; i>=n-t+1; i--)
		ans += (d[i]*p);
	printf("%.3lf",ans);
	
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值