Sdut 3061 Smart Maya (pressure DP)

Source: Internet
Author: User

Title Address: Sdut 3061

The background data of this game is wrong ... Good pit .... Don't spit the groove to the person.

I was wrong about the game and missed a situation. should be the shortest distance in all states required, and I was the idea is to choose two in front of the choice of two greedy ideas to form pressure, but sometimes can go up to the odd number and not all go, this situation is not right.

The correct idea is to find two each time not traversed state, divided into select one and choose two two cases to DP. Then finally find the number of the most in all States and the shortest distance. For each state, the number of passes can be preprocessed.

The code is as follows:

#include <iostream> #include <string.h> #include <math.h> #include <queue> #include < algorithm> #include <stdlib.h> #include <map> #include <stdio.h>using namespace Std;const double Inf=1e9;const double eqs=1e-5;int b[1<<17];d ouble dp[1<<17];struct Node {int x, y;} fei[32];d ouble dis T (node F1, node F2) {return sqrt ((f1.x-f2.x) * (f1.x-f2.x) *1.0+ (f1.y-f2.y) *1.0* (F1.Y-F2.Y));}        void init (int n, int tot) {int i, J;        Memset (b,0,sizeof (b));                                For (I=1, i<tot; i++) {for (j=0; j<n; J + +) {if (i& (1<<j)) {                        b[i]++;        }} Dp[i]=inf;        }}int Main () {int n, T, V, MAX1, TMP, I, J, K, Tmp1, tot;        Node St;        st.x=st.y=0; while (scanf ("%d%d%d", &n,&v,&t)!=eof) {for (i=0; i<n; i++) {scanf ("%d %d ", &fei[i].x,&AMP;FEI[I].Y);                } tot=1<<n;                Init (N,tot);                dp[0]=0; For (i=0, i<tot; i++) {for (j=0; j<n; J + +) {if (i& (1&LT;&L                                        T;J)) (==0) {tmp=i+ (1<<j);                                        Dp[tmp]=min (Dp[tmp],dp[i]+2*dist (st,fei[j));                                                        for (k=j+1; k<n; k++) {if ((tmp& (1<<k)) ==0) {                                                        tmp1=tmp+ (1<<k);                                                Dp[tmp1]=min (Dp[tmp1],dp[i]+dist (St,fei[j]) +dist (St,fei[k]) +dist (fei[j],fei[k]));                }                                        }                                }                        }                } double D;                d=t*v*1.0; //printf ("%d\n", D);                int max1=-1;                Double T, Min_d=inf;                        for (I=1; i<tot; i++) {if (DP[I]-D&GT;EQS) continue;                                if (Max1<b[i]) {max1=b[i];                        Min_d=dp[i];                        } else if (Max1==b[i]) {if (Min_d>dp[i]) min_d=dp[i];                }} t=min_d/v;        printf ("%d%.2f\n", max1,t);  } return 0;}


Sdut 3061 Smart Maya (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.