标签:res creat ble position normal map 二进制 virt otherwise
Input
Output
Sample Input
Sample Output
Source
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=55; 4 int ca,T,n,m,K,x,y,z,num,p[8],t[8],ft[8],pass[N],e[N][N],f[N][1<<8][1<<8]; 5 void Floyd() 6 { 7 for (int k=1;k<=n;++k) 8 for (int i=1;i<=n;++i) 9 for (int j=1;j<=n;++j) 10 if (i!=j&&j!=k&&k!=i) 11 e[i][j]=min(e[i][j],e[i][k]+e[k][j]); 12 } 13 int solve() 14 { 15 int ans=1e9; 16 f[1][0][0]=0; 17 for (int s1=0;s1<(1<<K);++s1) 18 for (int s2=0;s2<(1<<K);++s2) 19 for (int i=1;i<=n;++i) 20 { 21 int now=f[i][s1][s2]; 22 if (now>=1e9) continue; 23 if (s2==((1<<K)-1)) ans=min(ans,now+e[i][1]); 24 for (int j=0;j<K;++j) 25 if ((s2&(1<<j))==0) 26 { 27 int add=e[i][p[j]]; 28 if (s1&(1<<j)) add+=ft[j]; 29 else add+=t[j]; 30 f[p[j]][s1|pass[p[j]]][s2|(1<<j)]=min(f[p[j]][s1|pass[p[j]]][s2|(1<<j)],now+add); 31 } 32 for (int j=1;j<=n;++j) 33 { 34 int add=e[i][j]; 35 f[j][s1|pass[j]][s2]=min(f[j][s1|pass[j]][s2],now+add); 36 } 37 } 38 return ans; 39 } 40 int main() 41 { 42 scanf("%d",&T); 43 while (T--) 44 { 45 scanf("%d%d%d",&n,&m,&K); 46 memset(f,60,sizeof(f)); 47 memset(e,60,sizeof(e)); 48 memset(pass,0,sizeof(pass)); 49 for (int i=1;i<=n;++i) e[i][i]=0; 50 for (int i=1;i<=m;++i) 51 { 52 scanf("%d%d%d",&x,&y,&z); 53 e[x][y]=e[y][x]=z; 54 } 55 Floyd(); 56 for (int i=0;i<K;++i) 57 { 58 scanf("%d%d%d%d",&p[i],&t[i],&ft[i],&num); 59 for (int j=1;j<=num;++j) 60 { 61 scanf("%d",&x); 62 pass[x]|=1<<i; 63 } 64 } 65 printf("Case #%d: %d\n",++ca,solve()); 66 } 67 return 0; 68 }
标签:res creat ble position normal map 二进制 virt otherwise
原文地址:http://www.cnblogs.com/zk1431043937/p/7771815.html