|
- #include<iostream>
- #include<iomanip>
- #define FOR(i,a,b) for(register int i=a;i<=b;i++)
- #define ROF(i,a,b) for(register int i=a;i>=b;i--)
- using namespace std;
- const int N=2005,V=305,INF=0x7ffff;
- int n,m,v,e,c[N],d[N];
- double K[N],map[V][V],f[N][N][2],ans=double(INF);
- void Floyd_Warshall()
- {
- FOR(k,1,v)FOR(i,1,v)FOR(j,1,v)
- if(map[i][j]>map[i][k]+map[k][j])
- map[i][j]=map[i][k]+map[k][j];
- }
- int main()
- {
- cin>>n>>m>>v>>e;
- FOR(i,1,n)cin>>c[i];
- FOR(i,1,n)cin>>d[i];
- FOR(i,1,n)cin>>K[i];
- FOR(i,1,v)FOR(j,1,v)map[i][j]=double(INF);
- FOR(i,1,v)map[i][i]=0;
- FOR(i,1,e)
- {
- int a,b;double w;
- cin>>a>>b>>w;if(a==b)continue;
- map[a][b]=map[b][a]=min(map[a][b],w);
- }
- Floyd_Warshall();
- ///FOR(i,1,v){FOR(j,1,v)cout<<fixed<<setprecision(2)<<map[i][j]<<" ";cout<<endl;}
- /* if(m==0)
- {
- FOR(i,1,n)
- ans=ans+map[c[i]][c[i-1]];
- cout<<fixed<<setprecision(2)<<ans<<endl;
- return 0;
- }*/
- FOR(i,1,n)FOR(j,0,m)f[i][j][0]=f[i][j][1]=INF;
- f[1][0][0]=f[1][1][1]=0;
- FOR(i,2,n)
- {
- f[i][0][0]=f[i-1][0][0]+map[c[i-1]][c[i]];
- FOR(j,1,min(i,m))
- {
- int C1=c[i],C2=d[i],C3=c[i-1],C4=d[i-1];
- f[i][j][0]=min(f[i][j][0], min(f[i-1][j][0]+map[C3][C1],f[i-1][j][1]+map[C3][C1]*(1-K[i-1])+map[C4][C1]*K[i-1]));
- f[i][j][1]=min(f[i][j][1], min(f[i-1][j-1][0]+map[C3][C1]*(1-K[i])+map[C2][C3]*K[i],f[i-1][j-1][1]+map[C3][C1]*(1-K[i-1])*(1-K[i])+map[C3][C2]*(1-K[i-1])*K[i]+map[C4][C1]*K[i-1]*(1-K[i])+map[C4][C2]*K[i]*K[i-1]));
- }
- }
- ans=INF;
- FOR(i,0,m)
- ans=min(ans,min(f[n][i][0],f[n][i][1]));
- cout<<fixed<<setprecision(2)<<ans<<endl;
- return 0;
- }
复制代码 |
|