1119-pimp My Ride

Source: Internet
Author: User

1119-pimp My Ride
PDF (中文版) Statistics Forum
Time Limit:2 second (s) Memory limit:32 MB

Today, there is quite a few cars, motorcycles, trucks and other vehicles off there on the streets that would seriously Need some refurbishment. You are taken on this job, ripping off a few dollars from a major TV station along the. Of course, there's a lot of work to does, and you had decided that it ' s getting too much. Therefore you want to has the various jobs like painting, interior decoration and so on do by garages. Unfortunately, those garages is very specialized, so we need different garages for different jobs. They tend to charge you the more the better the overall appearance of the car is. That's, a painter might charge more for a car whose interior are all leather. As those "surcharges" depend on the what job was done and which jobs had been done before, you were currently trying to save Mo Ney by finding a optimal order for those jobs.

Individual jobs is numbered 1 through n. Given the base price p for each job and a surcharge s for every pair of jobs (i, J), meaning th At the additional s for job i, if and only if job J is completed before, you are T o Compute the minimum total costs needed to finish all jobs.

Input

Input starts with an integer T (≤100), denoting the number of test cases.

Each case starts with an integer n (1≤n≤14) denoting number of jobs. Then follow n lines, each containing exactly n integers. The ith line contains the surcharges, which has to be paid in garage number i for the ith job an D The base price for job I. More precisely, on the ith line, the ith integer was the base price for job I and the jth integer i≠j is the surcharge for job I that applies if job J have been done before. The prices is non-negative integers smaller than or equal to 100000.

Output

For each case, print the case number and the minimum total cost.

Sample Input Output for Sample Input

2

2

10 10

9000 10

3

14 23 0

0 14 0

1000 9500 14

Case 1:30

Case 2:42

Special Thanks:jane ALAM JAN (solution, DATASET) a simple pressure DP
1#include <stdio.h>2#include <string.h>3#include <algorithm>4#include <iostream>5#include <stdlib.h>6#include <math.h>7 using  namespacestd;8 intans[ -][ -];9 intdp[1<< -];Ten intMainvoid) One { A     inti,j,k; -scanf"%d",&k); -     ints; the     intn,m; -      for(s=1; s<=k; s++) -     { -scanf"%d",&n); +          for(i=0; i<n; i++) -         { +              for(j=0; j<n; J + +) A             { atscanf"%d",&ans[i][j]); -             } -         } -Fill (dp,dp+ (1<< -),1000000000); -dp[0]=0; -          for(i=0; i< (1&LT;&LT;N); i++) in         { -              for(j=0; j<n; J + +) to             { +                 if(i& (1<<j)) -                 { the                   intuu=i^ (1&LT;&LT;J);intsum=0; *                    for(intt=0; t<n;t++) $                   {Panax Notoginseng                       if(i& (1<<t)) -sum+=Ans[j][t]; the                   } +Dp[i]=min (dp[i],dp[uu]+sum); A                 } the             } +}printf ("Case %d:%d\n", s,dp[(1<<n)-1]); -}return 0; $}

1119-pimp My Ride

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.