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,&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<&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>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)