比赛 2017noip 评测结果 AAAAAAAAAAAAAAAAAAAAAAAAA
题目名称 换教室 最终得分 100
用户昵称 zhhe0101 运行时间 0.948 s
代码语言 C++ 内存使用 62.04 MiB
提交时间 2017-09-20 20:00:40
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
double ans=1e9;
int dis[305][305];
int n,m,v,e;
int c[2005],d[2005];
double k[2005],f[2005][2005][2];
double min(double x,double y)
{
	return x<y ? x : y;
}
void floyd()
{
	for (int kk=1;kk<=v;kk++)
		for (int i=1;i<=v;i++)
	    	for (int j=1;j<=v;j++)
	    	    if (i!=j&&kk!=i&&kk!=j)
	    			dis[i][j]=min(dis[i][j],dis[i][kk]+dis[kk][j]);
}
int main()
{
	freopen("classrooma.in","r",stdin);
	freopen("classrooma.out","w",stdout);
	int x,y,z;
	memset(dis,127/3,sizeof(dis));
	scanf("%d%d%d%d",&n,&m,&v,&e);
	for (int i=1;i<=n;i++)
	    scanf("%d",&c[i]);
	for (int i=1;i<=n;i++)
	    scanf("%d",&d[i]);
	for (int i=1;i<=n;i++)
	    scanf("%lf",&k[i]);
	for (int i=1;i<=e;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		if (dis[x][y]!=dis[0][0]) dis[x][y]=dis[y][x]=min(dis[x][y],z);
		else dis[x][y]=dis[y][x]=z;
	}
	floyd(); 
	for (int i=1;i<=n;i++)
	    for (int j=0;j<=m;j++)
		    f[i][j][0]=f[i][j][1]=1000000000.0;
	for (int i=0;i<=v;i++)
	    dis[0][i]=dis[i][0]=dis[i][i]=0;
	f[0][0][0]=0;
	f[1][0][0]=0;
	for (int i=2;i<=n;i++)
	    f[i][0][0]=f[i-1][0][0]+(double)dis[c[i-1]][c[i]];
	for (int i=1;i<=n;i++)
	    for (int j=1;j<=min(i,m);j++)
		{
			f[i][j][0]=min(f[i][j][0],f[i-1][j][1]+dis[d[i-1]][c[i]]*k[i-1]+dis[c[i-1]][c[i]]*(1-k[i-1]));
			f[i][j][0]=min(f[i][j][0],f[i-1][j][0]+dis[c[i-1]][c[i]]);
			f[i][j][1]=min(f[i][j][1],f[i-1][j-1][1]+dis[d[i-1]][d[i]]*k[i-1]*k[i]+dis[d[i-1]][c[i]]*k[i-1]*(1-k[i])+dis[c[i-1]][d[i]]*(1-k[i-1])*k[i]+dis[c[i-1]][c[i]]*(1-k[i-1])*(1-k[i]));
			f[i][j][1]=min(f[i][j][1],f[i-1][j-1][0]+dis[c[i-1]][d[i]]*k[i]+dis[c[i-1]][c[i]]*(1-k[i]));
//			printf("f[%d][%d][0]=%d    ",i,j,f[i][j][0]);
//			printf("f[%d][%d][1]=%d\n",i,j,f[i][j][1]);	
		} 
	for (int i=0;i<=m;i++)
	{
		ans=min(ans,f[n][i][0]);
		ans=min(ans,f[n][i][1]);
	}
	printf("%.2lf",ans);
}