![在这里插入图片描述](https://img-blog.csdnimg.cn/dc2c4f5fbe1d4fd4afe7e4bd4080a67e.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAWW9uY2hpb24=,size_20,color_FFFFFF,t_70,g_se,x_16)
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
vector<int> w[N];
vector<double> t[N];
double f[N];
double s[N];
double dp(int x)
{
if (f[x]>=0) return f[x];
f[x]=0;
for (int i=0;i<w[x].size();i++)
{
f[x]+=(t[x][i]+dp(w[x][i]))/s[x];
}
return f[x];
}
int main()
{
int n,m;
cin>>n>>m;
for (int i=0;i<m;i++)
{
int a,b,c;
cin>>a>>b>>c;
w[a].push_back(b);
t[a].push_back(c);
s[a]++;
}
memset(f,-1,sizeof f);
printf("%.2lf",dp(1));
return 0;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/e572397f9b7a4d45abaf4d36892345a8.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAWW9uY2hpb24=,size_20,color_FFFFFF,t_70,g_se,x_16)
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
#define endl "\n"
typedef long long ll;
typedef pair<int ,int> PII;
const double INF=1e20;
const int mod=1e9+7;
const int N=14;
int A,B,C,D;
double f[N][N][N][N][5][5];
double dp(int a,int b,int c, int d, int x,int y)
{
double &v=f[a][b][c][d][x][y];
if (v>=0) return v;
int as=a+(x==0)+(y==0);
int bs=b+(x==1)+(y==1);
int cs=c+(x==2)+(y==2);
int ds=d+(x==3)+(y==3);
if (as>=A&&bs>=B&&cs>=C&&ds>=D) return v=0;
int sum=a+b+c+d+(x!=4)+(y!=4);
sum=54-sum;
if (sum<=0) return v=INF;
v=1;
if (a<13) v+=(13.0-a)/sum*dp(a+1,b,c,d,x,y);
if (b<13) v+=(13.0-b)/sum*dp(a,b+1,c,d,x,y);
if (c<13) v+=(13.0-c)/sum*dp(a,b,c+1,d,x,y);
if (d<13) v+=(13.0-d)/sum*dp(a,b,c,d+1,x,y);
if(x==4)
{
double t=INF;
for (int i=0;i<4;i++)t=min(t,1.0/sum*dp(a,b,c,d,i,y));
v+=t;
}
if (y==4)
{
double t=INF;
for (int i=0;i<4;i++) t=min(t,1.0/sum*dp(a,b,c,d,x,i));
v+=t;
}
return v;
}
int main()
{
IOS;
cin>>A>>B>>C>>D;
memset(f,-1,sizeof f);
double t=dp(0,0,0,0,4,4);
if (t>INF/2) t=-1;
printf("%.3lf\n",t);
return 0;
}