C-hie with the pie
Time limit:2000 ms
Memory limit:65536kb
64bit Io format:% I64d & % i64usubmit statusappoint description: System crawler)
Description
The pizazz pizzeria prides itself in delivering pizzas to its customers as fast as possible. unfortunately, due to cutbacks, they can afford to hire only one driver to do the deliveries. he will wait for 1 or more (up to 10) orders to be processed before he starts any deliveries. needless to say, he wowould like to take the shortest route in delivering these goodies and returning to the pizzeria, even if it means passing the same location (s) or the pizzeria more than once on the way. he has commissioned you to write a program to help him.
Input
Input will consist of multiple test cases. The first line will contain a single integerNIndicating the number of orders to deliver, where 1 ≤N≤ 10. After this will beN+ 1 lines each containingN+ 1 integers indicating the times to travel between the pizzeria (numbered 0) andNLocations (numbers 1N).JTh value onITh line indicates the time to go directly from locationITo locationJWithout visiting any other locations along the way. Note that there may be quicker ways to go fromIToJVia other locations, due to different speed limits, traffic lights, etc. Also, the time values may not be between RIC, I. e., the time to go directly from locationIToJMay not be the same as the time to go directly from locationJToI. An input valueN= 0 will terminate input.
Output
For each test case, you shoshould output a single number indicating the minimum time to deliver all of the pizzas and return to the pizzeria.
Sample Input
30 1 10 101 0 1 210 1 0 1010 2 10 00
Sample output
8
From: http://blog.csdn.net/xymscau/article/details/6709588
Question: If a pizza is sent, no more than 10 places can be delivered each time. The minimum time required for sending a takeout to the store is required.
It's a bit Sb recently, and I often make sb mistakes. Today is another problem. This is an obvious DP, DP [I] [J]: indicates the minimum time to reach the J City when the I state (using binary to indicate whether the city has passed). The transfer equation is as follows: DP [I] [J] = min (DP [I] [k] + d [k] [J], DP [I] [J]) d [k] [J] is the shortest distance from K city to J City. It is clear that flody should be used first.
1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<algorithm> 6 #include<cmath> 7 #include<queue> 8 #include<map> 9 #include<vector> 10 11 #define N 105 12 #define M 100000 13 #define inf 1000000007 14 #define mod 1000000007 15 #define mod2 100000000 16 #define ll long long 17 #define maxi(a,b) (a)>(b)? (a) : (b) 18 #define mini(a,b) (a)<(b)? (a) : (b) 19 20 using namespace std; 21 22 int n; 23 int a[N][N]; 24 int d[N][N]; 25 int dp[ (1<<11)+10 ][N]; 26 int mi; 27 28 void flody() 29 { 30 int i,j,k; 31 for(k=0;k<n+1;k++){ 32 for(i=0;i<n+1;i++){ 33 for(j=0;j<n+1;j++){ 34 d[i][j]=min(d[i][j],d[i][k]+d[k][j]); 35 } 36 } 37 } 38 } 39 40 void ini() 41 { 42 int i,j; 43 // m=n+1; 44 mi=inf; 45 memset(dp,-1,sizeof(dp)); 46 for(i=0;i<=n;i++){ 47 for(j=0;j<=n;j++){ 48 scanf("%d",&a[i][j]); 49 d[i][j]=a[i][j]; 50 } 51 } 52 flody(); 53 } 54 55 56 57 void solve() 58 { 59 int o,j,p,te; 60 dp[0][0]=0; 61 for(o=0;o<(1<<n);o++){ 62 for(j=0;j<n;j++){ 63 if( ( (1<<j) & o)==0 ) continue; 64 if( (1<<j)==o ){ 65 dp[o][j+1]=d[0][j+1];continue; 66 } 67 dp[o][j+1]=inf; 68 te=o ^ (1<<j); 69 for(p=0;p<n;p++){ 70 if( ( (1<<p) & te)==0 ) continue; 71 dp[o][j+1]=min(dp[o][j+1],dp[te][p+1]+d[p+1][j+1]); 72 } 73 } 74 } 75 76 for(j=0;j<n;j++){ 77 mi=min(mi,dp[ (1<<n)-1 ][j+1]+d[j+1][0]); 78 } 79 80 //for(o=0;o<(1<<n);o++){ 81 // for(j=1;j<=n;j++) printf(" o=%d j=%d dp=%d\n",o,j,dp[o][j]); 82 //} 83 84 } 85 86 int main() 87 { 88 // freopen("data.in","r",stdin); 89 //freopen("data.out","w",stdout); 90 //scanf("%d",&T); 91 // for(int cnt=1;cnt<=T;cnt++) 92 // while(T--) 93 while(scanf("%d",&n)!=EOF) 94 { 95 if(n==0) break; 96 ini(); 97 solve(); 98 printf("%d\n",mi); 99 }100 return 0;101 }
Poj 3311 pressure DP Short Circuit