/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'int main()':
/in/foo.cc:29:21: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
  for(int s=0;s<(1<<n+1);s++)
                    ~^~
/in/foo.cc:37:21: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
  printf("%d",f[(1<<n+1)-1][0]);
                    ~^~
# 状态 耗时 内存占用
#1 Accepted 4ms 5.203 MiB
#2 Accepted 4ms 4.551 MiB
#3 Accepted 3ms 4.438 MiB
#4 Accepted 4ms 4.445 MiB
#5 Accepted 5ms 4.438 MiB
#6 Accepted 3ms 4.555 MiB
#7 Accepted 3ms 4.453 MiB
#8 Accepted 6ms 4.43 MiB
#9 Accepted 4ms 4.434 MiB
#10 Accepted 4ms 4.445 MiB

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 17;
#define inf 0x3f3f3f3f
inline int read(){
	int f=1,x=0;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return x*f;
}
#define read(x) x=read()
int n,full=(1<<16)-1,dis[maxn][maxn],f[1<<16][maxn];
int main(){
	read(n);
	for(int i=0;i<=n;i++)
	  for(int j=0;j<=n;j++) read(dis[i][j]);
	for(int k=0;k<=n;k++)
	  for(int i=0;i<=n;i++)
	    for(int j=0;j<=n;j++) dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	memset(f,inf,sizeof(f));
	f[0][0]=0;
	for(int s=0;s<(1<<n+1);s++)
	  for(int i=0;i<=n;i++){
	  	if((s&(1<<i))==0) continue;
	  	for(int j=0;j<=n;j++){
	  		//if((s&(1<<j))==0) continue;
	  		f[s][i]=min(f[s][i],min(f[s][j],f[s-(1<<i)][j])+dis[j][i]);
	  	}
	  }
	printf("%d",f[(1<<n+1)-1][0]);
	return 0;
}

信息

递交者
类型
递交
题目
送外卖
题目数据
下载
语言
C++
递交时间
2018-11-04 10:24:42
评测时间
2018-11-04 10:24:42
评测机
分数
100
总耗时
44ms
峰值内存
5.203 MiB