/ 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 12ms 10.355 MiB
#2 Accepted 18ms 10.25 MiB
#3 Accepted 13ms 10.25 MiB
#4 Accepted 26ms 10.344 MiB
#5 Accepted 22ms 10.367 MiB
#6 Accepted 23ms 10.25 MiB
#7 Accepted 15ms 10.375 MiB
#8 Accepted 29ms 10.367 MiB
#9 Accepted 12ms 10.332 MiB
#10 Accepted 11ms 10.344 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:24:28
评测时间
2017-11-06 21:24:28
评测机
分数
100
总耗时
186ms
峰值内存
10.375 MiB