记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Accepted 36ms 696.0 KiB
#2 Accepted 1ms 584.0 KiB
#3 Accepted 3ms 588.0 KiB
#4 Accepted 28ms 588.0 KiB
#5 Accepted 2ms 584.0 KiB
#6 Accepted 3ms 696.0 KiB
#7 Accepted 33ms 696.0 KiB
#8 Accepted 43ms 692.0 KiB
#9 Accepted 2ms 704.0 KiB
#10 Accepted 3ms 704.0 KiB
#11 Accepted 30ms 692.0 KiB
#12 Accepted 2ms 712.0 KiB
#13 Accepted 3ms 716.0 KiB
#14 Accepted 37ms 696.0 KiB
#15 Accepted 28ms 692.0 KiB
#16 Accepted 3ms 1.824 MiB
#17 Accepted 3ms 1.82 MiB
#18 Accepted 45ms 1.809 MiB
#19 Accepted 30ms 1.941 MiB
#20 Accepted 10ms 8.438 MiB
#21 Wrong Answer 10ms 8.5 MiB
#22 Accepted 11ms 8.574 MiB
#23 Accepted 20ms 17.57 MiB
#24 Accepted 61ms 33.25 MiB
#25 Accepted 81ms 61.969 MiB

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn=2010;
const double inf=1<<17;
int n,m,v,e;
int a[maxn][2];
int f[310][310];
double k[maxn],dp[maxn][maxn][2];

void Floyd()
{
  for(int i=1;i<=v;i++) f[i][i]=0;
  for(int k=1;k<=v;k++)
    for(int i=1;i<=v;i++)
      for(int j=1;j<=v;j++)
        f[i][j]=min(f[i][j],f[i][k]+f[k][j]);
}
int main()
{
  int x,y,w;
  memset(f,0x3f,sizeof(f));
  scanf("%d %d %d %d",&n,&m,&v,&e);
  for(int i=1;i<=n;i++) scanf("%d",&a[i][0]);
  for(int i=1;i<=n;i++) scanf("%d",&a[i][1]);
  for(int i=1;i<=n;i++) scanf("%lf",&k[i]);
  for(int i=1;i<=e;i++)
  {
  	scanf("%d %d %d",&x,&y,&w);
  	f[x][y]=f[y][x]=min(f[x][y],w);
  }
  Floyd();
  for(int i=0;i<=n;i++)
    for(int j=0;j<=m;j++)
      dp[i][j][0]=dp[i][j][1]=inf;
  dp[1][0][0]=dp[1][1][1]=0;
  for(int i=2;i<=n;i++)
  {
  	int C1=a[i-1][0],C2=a[i-1][1],C3=a[i][0],C4=a[i][1];
  	dp[i][0][0]=dp[i-1][0][0]+f[C1][C3];
  	for(int j=1;j<=min(i,m);j++)
    {
      dp[i][j][0]=min(dp[i][j][0],min(dp[i-1][j][0]+f[C1][C3],dp[i-1][j][1]+(1-k[i-1])*f[C1][C3]+k[i-1]*f[C2][C3]));
      dp[i][j][1]=min(dp[i][j][1],dp[i-1][j-1][0]+k[i]*f[C1][C4]+(1-k[i])*f[C1][C3]);
      dp[i][j][1]=min(dp[i][j][1],dp[i-1][j-1][1]+(1-k[i-1])*(1-k[i])*f[C1][C3]+k[i-1]*(1-k[i])*f[C2][C3]+(1-k[i-1])*k[i]*f[C1][C4]+k[i-1]*k[i]*f[C2][C4]);
	}
  }
  double ans=inf;
  for(int i=0;i<=m;i++) 
    ans=min(ans,min(dp[n][i][0],dp[n][i][1])); 
  printf("%.2lf\n",ans);
  return 0;
}

信息

递交者
类型
递交
题目
P1005 换教室
比赛
随机真题赛第二轮(xhy&lfy讲题)
题目数据
下载
语言
C++
递交时间
2019-11-12 08:54:27
评测时间
2019-11-12 08:54:34
评测机
分数
96
总耗时
539ms
峰值内存
61.969 MiB