Codevs 2800 off-sell

Source: Internet
Author: User

/*F[i][j] represents the optimal solution of the point of the past that constitutes I state and the last point reached is J when the last State is (1<<n+1)-1 each point arrives at this back to 0*/#include<iostream>#include<cstdio>#include<cstring>#defineMAXN 100010//minimum to 1<<16using namespacestd;intn,g[ -][ -],f[maxn][ -],ans=0x3f3f3f3f;intMain () {scanf ("%d",&N);  for(intI=0; i<=n;i++)       for(intj=0; j<=n;j++) scanf ("%d",&G[i][j]);  for(intk=0; k<=n;k++)       for(intI=0; i<=n;i++)         for(intj=0; j<=n;j++) G[i][j]=min (g[i][k]+G[k][j],g[i][j]); Memset (F,127/3,sizeof(f)); f[1][0]=0;//Initialize     for(intI=1; I<= (1<<n+1)-1; i++)//enumerate the state of the traversed point composition       for(intj=0; j<=n;j++)//enumerates the last point reached        if((1&LT;&LT;J) &i)//J walked.          {               for(intk=0; k<=n;k++) F[i| (1<<k)][k]=min (f[i| (1&LT;&LT;K)][k],f[i][j]+G[j][k]); }     for(intI=1; i<=n;i++) ans=min (ans,g[i][0]+f[(1<<n+1)-1][i]); printf ("%d\n", ans); return 0;}

Codevs 2800 off-sell

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.