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 |
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的更多相关文章
- lightoj 1119 - Pimp My Ride(状压dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1119 题解:状压dp存一下车有没有被搞过的状态就行. #include < ...
- 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, ...
- LightOJ1119 Pimp My Ride(状压DP)
dp[S]表示已经完成的工作集合 枚举从哪儿转移过来的,再通过枚举计算花费..水水的.. #include<cstdio> #include<cstring> #include ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- Google服务器架构图解简析
无疑是互联网时代最闪亮的明星.截止到今天为止,Google美国主站在Alexa排名已经连续3年第一,Alexa Top100中,各国的Google分站竟然霸占了超过20多个名额,不得不令人感叹Goog ...
- 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 ...
- RIDE小技巧——Content Assistance快捷键(CTRL+空格)的修改
大家在用RIDE Content Assistance功能的快捷键时会与机器中是输入法的切换相冲突,这里提供一下修改的位置,大家可以根据个人的喜好修改. 有三处需要修改: {Python_home}\ ...
- RIDE -- Robot Framework setup
RobotFramework 是一款基于python 的可以实现关键字驱动和数据驱动并能够生成比较漂亮的测试报告的一款测试框架 这里使用的环境是 python-2.7.10.amd64.msi RID ...
- RobotFrameWork(二)Ride简单使用及快捷键
一.简单示例 注意:以下操作使用到快捷键的,请先确保没有与其他软件的快捷键设置冲突,比如sogou拼音.有道词典等等 1.启动ride 启动ride方法: 1) 通过界面图标 2) dos命令行: ...
随机推荐
- svn简单上传下载文件命令
上传命令: svn import 本地文件或目录 远程服务端目录 --username '用户名' --password '密码' -m '添加描述(可为空)' 下载命令: svn export 远程 ...
- 【Redis集群原理专题】分析一下相关的Redis集群模式下的脑裂问题!
技术格言 世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程. 什么是脑裂 字面含义 首先,脑裂从字面上理解就是脑袋裂开了,就是思想分家了,就是有了两个山头,就是有了 ...
- 我的分布式微服务框架:YC-Framework
YC-Framework官方文档:http://framework.youcongtech.com/ YC-Framework源代码:https://github.com/developers-you ...
- IPFS是什么?IPFS原理、IPFS存储
以下内容调研截止到2021/11/5日 IPFS简介 IPFS是一种内容可寻址.点对点.分布式文件系统.IPFS采用内容-地址寻址技术,即通过文件内容进行检索而不是通过文件的网络地址.简单来说,就是对 ...
- 19. 删除链表的倒数第 N 个结点
目录 19.删除链表的倒数第N个节点 题目 题解-暴力 题解-哈希表 题解-双指针 19.删除链表的倒数第N个节点 题目 给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点. 输入:he ...
- A Child's History of England.43
PART THE SECOND When the King heard how Thomas à Becket had lost his life in Canterbury Cathedral, t ...
- 零基础学习java------31---------共享单车案例,html快速入门(常见标签,get和post的区别)
一 .单车案例 二. HTML快速入门 红字表示要掌握的内容 超文本标记语言,此处的标记指的即是关键字,其用处是用来写页面(展示数据). 语法:(1)./当前目录:../ 父级目录 (2)注释符号: ...
- [JAVA]动态代理与AOP的千丝万缕
动态代理与AOP的联系 别的不说,直接上图 首先是AOP切面编程 什么是切面?(自己心里想想就ok)所以所谓的切面编程,你也就懂得大体了,只是这个被切的是个程序而已 那么AOP与动态代理有什么关系呢? ...
- Android给页面添加横线和竖线
竖线 <View android:layout_width="1dip" android:layout_height="match_parent& ...
- 【kafka学习笔记】kafka的基本概念
在了解了背景知识后,我们来整体看一下kafka的基本概念,这里不做深入讲解,只是初步了解一下. kafka的消息架构 注意这里不是设计的架构,只是为了方便理解,脑补的三层架构.从代码的实现来看,kaf ...