1119 - Pimp My Ride
Time Limit: 2 second(s) Memory Limit: 32 MB

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

Individual jobs are numbered 1 through n. Given the base price p for each job and a surcharge s for every pair of jobs (i, j), meaning that you have to pay additional s for job i, if and only if job j was completed before, you are to 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 that have to be paid in garage number i for the ith job and the base price for job i. More precisely, on the ith line, the ith integer is the base price for job i and the jth integer i ≠ j is the surcharge for job i that applies if job j has been done before. The prices will be 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)
一道简单的状压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 namespace std;
8 int ans[20][20];
9 int dp[1<<20];
10 int main(void)
11 {
12 int i,j,k;
13 scanf("%d",&k);
14 int s;
15 int n,m;
16 for(s=1; s<=k; s++)
17 {
18 scanf("%d",&n);
19 for(i=0; i<n; i++)
20 {
21 for(j=0; j<n; j++)
22 {
23 scanf("%d",&ans[i][j]);
24 }
25 }
26 fill(dp,dp+(1<<20),1000000000);
27 dp[0]=0;
28 for(i=0; i<(1<<n); i++)
29 {
30 for(j=0; j<n; j++)
31 {
32 if(i&(1<<j))
33 {
34 int uu=i^(1<<j);int sum=0;
35 for(int t=0;t<n;t++)
36 {
37 if(i&(1<<t))
38 sum+=ans[j][t];
39 }
40 dp[i]=min(dp[i],dp[uu]+sum);
41 }
42 }
43 }printf("Case %d: %d\n",s,dp[(1<<n)-1]);
44 }return 0;
45 }

1119 - Pimp My Ride的更多相关文章

  1. lightoj 1119 - Pimp My Ride(状压dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1119 题解:状压dp存一下车有没有被搞过的状态就行. #include < ...

  2. HOJ 2317 Pimp My Ride(状态压缩DP)

    Pimp My Ride My Tags (Edit) Source : TUD 2005 Time limit : 3 sec Memory limit : 64 M Submitted : 63, ...

  3. LightOJ1119 Pimp My Ride(状压DP)

    dp[S]表示已经完成的工作集合 枚举从哪儿转移过来的,再通过枚举计算花费..水水的.. #include<cstdio> #include<cstring> #include ...

  4. HOJ题目分类

    各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...

  5. Google服务器架构图解简析

    无疑是互联网时代最闪亮的明星.截止到今天为止,Google美国主站在Alexa排名已经连续3年第一,Alexa Top100中,各国的Google分站竟然霸占了超过20多个名额,不得不令人感叹Goog ...

  6. USACO . Your Ride Is Here

    Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...

  7. RIDE小技巧——Content Assistance快捷键(CTRL+空格)的修改

    大家在用RIDE Content Assistance功能的快捷键时会与机器中是输入法的切换相冲突,这里提供一下修改的位置,大家可以根据个人的喜好修改. 有三处需要修改: {Python_home}\ ...

  8. RIDE -- Robot Framework setup

    RobotFramework 是一款基于python 的可以实现关键字驱动和数据驱动并能够生成比较漂亮的测试报告的一款测试框架 这里使用的环境是 python-2.7.10.amd64.msi RID ...

  9. RobotFrameWork(二)Ride简单使用及快捷键

    一.简单示例 注意:以下操作使用到快捷键的,请先确保没有与其他软件的快捷键设置冲突,比如sogou拼音.有道词典等等 1.启动ride 启动ride方法: 1)  通过界面图标 2)  dos命令行: ...

随机推荐

  1. SonarQube的部分规则探讨

    引言:为了更好的使项目代码规范化,减少Bug的出现,因此最近引入了SonarQube来帮助检测代码问题,这里就分享部分有趣的规则. 注:因为保密原则,文章贴出来的代码都是我按照格式仿写的,并非公司源码 ...

  2. C/C++ Qt StandardItemModel 数据模型应用

    QStandardItemModel 是标准的以项数据为单位的基于M/V模型的一种标准数据管理方式,Model/View 是Qt中的一种数据编排结构,其中Model代表模型,View代表视图,视图是显 ...

  3. C# / VB.NET 在Word中嵌入多媒体(视频、音频)文件

    Word中可将Office(Word/Excel/PowerPoint).PDF.txt等文件作为OLE对象插入到文档中,双击该对象可直接访问或编辑该文件,除了以上常见的文件格式对象,也可以插入多媒体 ...

  4. ceph安装部署

    环境准备 测试环境是4台虚拟机,所有机器都是刚刚安装好系统(minimal),只配置完网卡和主机名的centos7.7,每个osd增加一块磁盘,/dev/sdb ceph-admin ---- adm ...

  5. 爬虫系列:连接网站与解析 HTML

    这篇文章是爬虫系列第三期,讲解使用 Python 连接到网站,并使用 BeautifulSoup 解析 HTML 页面. 在 Python 中我们使用 requests 库来访问目标网站,使用 Bea ...

  6. c++string转const char*与char*

    #include <iostream> #include <string> #include <memory> using namespace std; const ...

  7. Linux 设置时区

    一.查看和修改Linux的时区 1. 查看当前时区命令 : "date -R" 2. 修改设置Linux服务器时区方法 A命令 : "tzselect" 方法 ...

  8. Default Constructors

    A constructor without any arguments or with default value for every argument, is said to be default ...

  9. 类型类 && .class 与 .getClass() 的区别

    一. 什么是类型类 Java 中的每一个类(.java 文件)被编译成 .class 文件的时候,Java虚拟机(JVM)会为这个类生成一个类对象(我们姑且认为就是 .class 文件),这个对象包含 ...

  10. 【代码优化】List.remove() 剖析

    一.犯错经历 1.1 故事背景 最近有个需求大致的背景类似: 我已经通过一系列的操作拿到一批学生的考试成绩数据,现在需要筛选成绩大于 95 分的学生名单. 善于写 bug 的我,三下五除二完成了代码的 ...