UVA-10911 Forming Quiz Teams

Source: Internet
Author: User

The main topic: there are 2 * n points, so that they make up n pairs, the sum of the minimum distance of N to the point set.

Problem-solving ideas: Because 2 * n maximum is 20, can be represented by the number of bits, each number represents a state, and then to the memory of the search method to produce results.

#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace STD;intNDoubledp[1<< -], dis[ -][ -];DoubleCalintXintY) {return sqrt(x * x + y * y);}DoubleDPS (intS) {if(Dp[s] | |! SreturnDp[s];intI for(i = N-1; I >=0; i--)if(S & (1<< i)) Break; Dp[s] =0x3f3f3f3f; for(intj = i-1; J >=0; j--)if(S & (1<< j)) Dp[s] = min (Dp[s], dis[i][j] + DPS (S ^ (1<< i) ^ (1<< (j)));returnDp[s];}intMain () {intx[ -], y[ -], Kase =0; while(scanf("%d", &n), n) {n <<=1; for(inti =0; i < N; i++)scanf("%*s%d%d", &x[i], &y[i]); for(inti =0; i < N; i++) for(intj = i +1; J < N; J + +) Dis[j][i] = cal (X[i]-x[j], Y[i]-y[j]);memset(DP,0,sizeof(DP));printf("Case%d:%.2lf\n", ++kase, DPS (1<< N)-1)); }return 0;}

UVA-10911 Forming Quiz Teams

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.