/ Randle /

记录详情

Accepted

/in/foo.cc: In function 'int main()':
/in/foo.cc:37:24: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
     for(int k=1;k<(1<<n+1);k++)
                       ~^~
/in/foo.cc:59:30: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
      printf("%d\n",f[0][(1<<n+1)-1]);
                             ~^~
# 状态 耗时 内存占用
#1 Accepted 9ms 10.359 MiB
#2 Accepted 9ms 10.367 MiB
#3 Accepted 9ms 10.25 MiB
#4 Accepted 12ms 10.199 MiB
#5 Accepted 16ms 10.25 MiB
#6 Accepted 10ms 10.25 MiB
#7 Accepted 11ms 10.328 MiB
#8 Accepted 25ms 10.25 MiB
#9 Accepted 12ms 10.348 MiB
#10 Accepted 13ms 10.371 MiB

代码

#include<iostream>

#include<cstdio>

#include<cstring>

using namespace std;

int n;

int a[20][20];

int f[20][(1<<17)+56];

int main()

{

scanf("%d",&n);

for(int i=0;i<=n;i++) 

for(int j=0;j<=n;j++)  scanf("%d",&a[i][j]);

for(int k=0;k<=n;k++)

   for(int i=0;i<=n;i++)

       for(int j=0;j<=n;j++)  

           if(i!=k && j!=k && i!=j)  a[i][j]=min(a[i][j],a[i][k]+a[k][j]);

memset(f,127/3,sizeof(f));

  f[0][0]=0;

    for(int k=1;k<(1<<n+1);k++)

    {

    for(int i=0;i<=n;i++)

    {

   if((1<<i) &k) 

    for(int j=0;j<=n;j++)

    {

    f[i][k]=min(f[i][k],f[j][k-(1<<i)]+a[j][i]);

    }

    }

    }

     printf("%d\n",f[0][(1<<n+1)-1]);

     return 0;

 }

信息

递交者
类型
递交
题目
送外卖
题目数据
下载
语言
C++
递交时间
2017-11-06 21:29:08
评测时间
2017-11-06 21:29:08
评测机
分数
100
总耗时
130ms
峰值内存
10.371 MiB