• bzoj3380 [USACP2004 Open]Cave Cow 1洞穴里的牛之一


    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3380

    题目大意:


    题解:

    floyd+状压dp

    n<=100所以直接先用floyd预处理要从i到j最多能吃到多胖

    f[i][j]表示已经吃了哪些洞穴(只是指有食物的那些洞穴)的食物(i为二进制表状态),且走到了Cj号洞穴能吃到的最多的食物。

    因为最后要回到1号洞穴,所以如果1号洞穴有食物都最后吃肯定能得到一个最优解。(怕一开始吃太胖233= =)

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    
    const int inf = 0x7fffffff;
    int mymin(int x,int y){return (x<y)?x:y;}
    int mymax(int x,int y){return (x>y)?x:y;}
    int f[1<<15][110];
    int map[110][110],c[110];
    int main()
    {
    	//freopen("cavecow.in","r",stdin);
    	//freopen("cavecow.out","w",stdout);
    	int n,m,k,kk,i,j,ans,mx,x,y,w;
    	scanf("%d%d%d",&n,&m,&kk);
    	for (i=1;i<=kk;i++) scanf("%d",&c[i]);
    	for (i=1;i<=n;i++)
    	 for (j=i+1;j<=n;j++) map[i][j]=map[j][i]=inf;
    	for (i=1;i<=m;i++)
    	{
    		scanf("%d%d%d",&x,&y,&w);
    		map[x][y]=mymin(map[x][y],w);
    		map[y][x]=map[x][y];
    	}
    	for (k=1;k<=n;k++)//floyd
    	 for (i=1;i<=n;i++) if (i!=k)
    	  for (j=1;j<=n;j++) if (j!=i && j!=k)
    	    if (map[i][j]!=inf) map[i][j]=mymax(map[i][j],mymin(map[i][k],map[k][j]));
    		else map[i][j]=mymin(map[i][k],map[k][j]);
    	mx=(1<<kk)-1;
    	f[1][1]=0;ans=0;
    	for (i=1;i<=mx;i++)
    	 for (j=1;j<=kk;j++)
    	  if (i&(1<<j-1))
    	  {
    		  for (k=1;k<=kk;k++)
    			if (!(i&(1<<k-1)))
    			{
    				if (map[c[j]][c[k]]<f[i][j]) continue;
    				f[i|(1<<k-1)][k]=mymax(f[i|(1<<k-1)][k],f[i][j]+1);
    			}
    		  if (map[c[j]][1]>=f[i][j]) ans=mymax(ans,f[i][j]);
    	  }
    	for (i=1;i<=kk;i++) if (c[i]==1) {ans++;break;}//最后看下1号洞穴有没有食物而已
    	printf("%d
    ",ans);
    	return 0;
    }


  • 相关阅读:
    OpenCascade Ray Tracing Rendering
    Create New Commands in Tcl
    OpenCascade Modeling Algorithms Fillets and Chamfers
    OpenCascade Modeling Algorithms Boolean Operations
    Construction of Primitives in Open Cascade
    Open Cascade Data Exchange STL
    Tcl Tk Introduction
    Open Cascade DataExchange IGES
    Netgen mesh library : nglib
    Hello Netgen
  • 原文地址:https://www.cnblogs.com/Euryale-Rose/p/6527844.html
Copyright © 2020-2023  润新知