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命令行: ...
随机推荐
- Redis集合解决大数据筛选
Redis集合:集合是什么,就是一堆确定的数据放在一起,数学上集合有交集.并集的概念,这个就可以用来做大数据的筛选功能. 以商品为例,假如商品有颜色和分类.价格区间等属性. 给所有统一颜色的商品放一个 ...
- [云原生]Docker - 简介
目录 什么是Docker? 为什么使用Docker? 对比传统虚拟机总结 什么是Docker? Docker是一个开源项目,诞生于2013年初,最初是dotCloud公司内部的一个业务项目.它基于Go ...
- 启动spark-shell --master yarn的bug
报错如下 18/06/06 15:55:31 ERROR cluster.YarnClientSchedulerBackend: Yarn application has already exited ...
- Flink(二)【架构原理,组件,提交流程】
目录 一.运行架构 1.架构 2.组件 二.核心概念 TaskManager . Slots Parallelism(并行度) Task .Subtask Operator Chains(任务链) E ...
- Spark(九)【RDD的分区和自定义Partitioner】
目录 spark的分区 一. Hash分区 二. Ranger分区 三. 自定义Partitioner 案例 spark的分区 Spark目前支持Hash分区和Range分区,用户也可以自定义分区 ...
- nodejs-Express框架
JavaScript 标准参考教程(alpha) 草稿二:Node.js Express框架 GitHub TOP Express框架 来自<JavaScript 标准参考教程(alpha)&g ...
- 【Linux】【Services】【VersionControl】git-daemon, httpd, mysql搭建带认证的gitserver
1. 简介: 比较低端的gitserver,使用centos自带的git-daemon搭建gitserver,使用httpd做上传和下载,利用mod_auth_mysql做认证 2. 环境 # Apa ...
- SpringAOP简单例子
这个只是个简单AOP例子,包括前置通知,后置通知,环绕通知,和目标对象.写这个例子的主要目标只是想让想学AOP的能更快地入门,了解一下如何去配置AOP里面的东东.目标对象的接口:IStudent.ja ...
- 【spring AOP】@Pointcut的12种用法
@Pointcut用来标注在方法上来定义切入点. 使用格式:@ 注解(value="表达标签 (表达式格式)").如:@Pointcut("execution(* com ...
- Servlet+Jdbc+mysql实现登陆功能
首先是新建一个servlet,servlet中有dopost和doget方法 一般的表格提交都是用post方法,故在dopost里面写入逻辑代码 下面是其逻辑代码Check.java protecte ...