/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'void spfa()':
/in/foo.cc:40:20: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
    if(dis[i][p|1<<i-1]>dis[k][p]+len[k][i])
                   ~^~
/in/foo.cc:42:19: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
     dis[i][p|(1<<i-1)]=dis[k][p]+len[k][i];
                  ~^~
/in/foo.cc:43:26: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
     if(!in_que[i][p|(1<<i-1)])
                         ~^~
/in/foo.cc:45:25: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
      path.push(i,p|(1<<i-1));
                        ~^~
/in/foo.cc:46:23: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
      in_que[i][p|(1<<i-1)]=true;
                      ~^~
# 状态 耗时 内存占用
#1 Accepted 6ms 5.844 MiB
#2 Accepted 5ms 5.465 MiB
#3 Accepted 4ms 5.344 MiB
#4 Accepted 8ms 6.109 MiB
#5 Accepted 11ms 6.113 MiB
#6 Accepted 5ms 5.363 MiB
#7 Accepted 6ms 5.344 MiB
#8 Accepted 18ms 6.125 MiB
#9 Accepted 8ms 5.734 MiB
#10 Accepted 8ms 5.855 MiB

代码

#include<bits/stdc++.h>
inline const void read(int &a)
{
	a=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
}
int n,len[16][16],dis[16][1<<16];
bool in_que[16][1<<16];
struct queue
{
	int que[100000],cond[100000],start,end;
	inline const void init(){start=0;end=-1;}
	inline const bool empty(){if(start>end)return true;return false;}
	inline const void push(int a,int b){que[++end]=a;cond[end]=b;}
	inline const void pop(){in_que[que[start]][cond[start]]=false;start++;}
	inline const int front_que(){return que[start];}
	inline const int front_cond(){return cond[start];}
}path;
void spfa()
{
	while(!path.empty())
	{
		int k=path.front_que(),p=path.front_cond();
		if(dis[0][p]>dis[k][p]+len[k][0])
		{	
			dis[0][p]=dis[k][p]+len[k][0];
			if(!in_que[0][p])
			{
				path.push(0,p);
				in_que[0][p]=true;
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(dis[i][p|1<<i-1]>dis[k][p]+len[k][i])
			{	
				dis[i][p|(1<<i-1)]=dis[k][p]+len[k][i];
				if(!in_que[i][p|(1<<i-1)])
				{
					path.push(i,p|(1<<i-1));
					in_que[i][p|(1<<i-1)]=true;
				}
			}
		}
		path.pop();
	}
}
int main()
{
	path.init();
	memset(in_que,false,sizeof(in_que));
	read(n);
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)read(len[i][j]);
	memset(dis,0x7f,sizeof(dis));
	dis[0][0]=0;path.push(0,0);in_que[0][0]=true;
	spfa();
	std::cout<<dis[0][(1<<n)-1];
	return 0;
}

信息

递交者
类型
递交
题目
送外卖
题目数据
下载
语言
C++
递交时间
2017-10-09 20:45:38
评测时间
2017-10-09 20:45:38
评测机
分数
100
总耗时
85ms
峰值内存
6.125 MiB