Hie with the Pie (POJ 3311 pressure DP)

Source: Internet
Author: User

Test instructions: Pizza shop gives pizza to n places, the time it takes to spend between places (including the pizzeria), and the minimum time it takes to send all the places and back to the store

Analysis: The state is ok dp[i][j],i in 1 means that the place has been sent, otherwise 0,j for the current state of the last place to send, pay attention to how to walk only calculate the minimum time, of course, the shortest way, point rarely by Floyd to find out the most short-circuited points

For the minimum time to return to the store, depart from the store (status 1).

#include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <string> #include <cctype> #include <complex> #include <cassert> #include <utility> #include <cstring> #include <cstdlib># Include <iostream> #include <algorithm>using namespace std;typedef pair<int,int> pii;typedef long Long ll; #define Lson l,m,rt<<1#define Pi ACOs ( -1.0) #define Rson m+1,r,rt<<11#define all 1,n,1#define read fre Open ("In.txt", "R", stdin) const LL INFLL = 0x3f3f3f3f3f3f3f3fll;const int inf= 0x7ffffff;const int mod = 1000000007;int    D[15][15],a[15][15],n,dp[2500][15];void solve () {int c= (1<< (n+1))-1; for (int k=0;k<=n;++k) for (int. i=0;i<=n;++i) for (int j=0;j<=n;++j) d[i][j]=min (d[i][j],d[i][k    ]+D[K][J]);    Memset (Dp,-1,sizeof (DP));    dp[1][0]=0;  for (int i=1;i<=c;++i) {i|=1;  for (int j=0;j<=n;++j) {if (dp[i][j]==-1) continue; for (int k=0;k<=n;++k) if (dp[i| ( 1<<k)][k]==-1&&j!=k| | Dp[i| ( 1<<k)][k]>dp[i][j]+d[j][k]) dp[i| (    1<<k)][k]=dp[i][j]+d[j][k]; }} printf ("%d\n", Dp[c][0]);}        int main () {while (~SCANF ("%d", &n)) {if (n==0) break;        for (int i=0;i<=n;++i) for (int j=0;j<=n;++j) scanf ("%d", &d[i][j]);    Solve (); }return 0;}

  

Hie with the Pie (POJ 3311 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.