http://172.20.6.3/Problem_Show.asp?id=1457
I don't know why I pushed backwards to expect only 80 points, so I compromised, I wrote a positive, I was guilty.
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <cmath>5#include <iostream>6#include <queue>7 using namespacestd;8 Const intmaxn= .;9 intt,k,n,m;Ten intc[2][maxn]={}; One intdis[310][310]={}; A intvis[maxn]={}; - Doublef[maxn][maxn][2]; - Doubleke[maxn]={}; the intMain () { - //freopen ("wtf.in", "R", stdin); -scanf"%d%d%d%d",&t,&k,&n,&m); - intx,y,v; + for(intI=1; i<=t;i++){ -scanf"%d", &c[0][i]); + } A for(intI=1; i<=t;i++){ atscanf"%d", &c[1][i]); - } - for(intI=1; i<=t;i++){ -scanf"%LF",&ke[i]); - } -memset (DIS, the,sizeof(DIS)); in for(intI=1; i<=n;i++) dis[i][i]=0; - for(intI=1; i<=m;i++){ toscanf"%d%d%d",&x,&y,&v); +dis[x][y]=min (dis[x][y],v); -dis[y][x]=Dis[x][y]; the } * for(intI=1; i<=n;i++){ $ for(intj=1; j<=n;j++){Panax Notoginseng if(I==J)Continue; - for(intw=1; w<=n;w++){ the if(dis[j][i]+dis[i][w]<Dis[j][w]) { +dis[j][w]=dis[j][i]+Dis[i][w]; A } the } + } - } $ for(intI=1; i<=n;i++) dis[i][0]=dis[0][i]=0; $ for(intI=0; i<=t;i++){ - for(intj=0; j<=k;j++){ -f[i][j][1]=20000000000.0; thef[i][j][0]=20000000000.0; - }Wuyi}Doubleans=f[0][0][0]; thef[1][0][0]=f[1][1][1]=0; - for(intI=2; i<=t;i++){ Wu intMa=min (i,k); -f[i][0][0]=f[i-1][0][0]+dis[c[0][i-1]][c[0][i]]; About for(intj=1; j<=ma;j++){ $f[i][j][0]=min (f[i-1][j][0]+dis[c[0][i-1]][c[0][i]],f[i-1][j][1]+dis[c[1][i-1]][c[0][i]]*ke[i-1]+dis[c[0][i-1]][c[0][i]]* (1.0-ke[i-1])); -f[i][j][1]=min (f[i-1][j-1][0]+dis[c[0][i-1]][c[1][i]]*ke[i]+dis[c[0][i-1]][c[0][i]]* (1-Ke[i]), -f[i-1][j-1][1]+dis[c[1][i-1]][c[1][i]]*ke[i]*ke[i-1]+dis[c[1][i-1]][c[0][i]]*ke[i-1]*(1.0-Ke[i]) -+dis[c[0][i-1]][c[1][i]]* (1.0-ke[i-1]) *ke[i]+dis[c[0][i-1]][c[0][i]]* (1.0-ke[i]) * (1.0-ke[i-1])); A } + } the for(intI=0; i<=k;i++){ -Ans=min (Ans,min (f[t][i][0],f[t][i][1])); $ } theprintf"%.2f", ans); the return 0; the}View Code
JZYZOJ1457 [NOIP2016] Change classroom expected DP dynamic programming Floyd algorithm shortest circuit