HLG 2130-Shape pressure DP

Source: Internet
Author: User

The basic pressure DP needs to be noted that the shortest line between two points does not need to be Floyd

Due to the DP Memset placed in the initialization of 0 after the de for a long time the bug.

#include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> #include <map    >using namespace std; #define EQS 0.000000001struct node{double x; Double y;};    Node a[20];d ouble f[20][20];d ouble dp[1<<17][20];int main () {int t;scanf ("%d", &t), while (t--) {int n;    scanf ("%d", &n);    memset (F,0,sizeof (f));    for (int i=0;i<n;i++) {scanf ("%lf%lf", &a[i].x,&a[i].y); } for (int i=0;i<n;i++) {for (int k=0;k<n;k++) {f[i][k]=f[k][i]=sqrt (a[i].x-a[k].x)        * (a[i].x-a[k].x) + (A[I].Y-A[K].Y) * (A[I].Y-A[K].Y));    }} int l= (1<<n)-1;    Memset (Dp,0x7f,sizeof (DP));    for (int i=0;i<n;i++) {dp[1<<i][i]=0;            } for (int s=0;s<=l;s++) {for (int i=0;i<n;i++) {if ((s& (1<<i)) ==0)            Continue for (int k=0;k<n;k++) {if ((s& (1<<k))!=0) continue;            dp[s+ (1<<k)][k]=min (dp[s+ (1<<k)][k],dp[s][i]+f[i][k]);    }}} double ans=1e300;   for (int i=0;i<n;i++) {ans=min (Dp[l][i],ans); } printf ("%.2f\n", ans);}}

  

HLG 2130-Shape pressure DP

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.