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命令行: ...
随机推荐
- 使用 CliWrap 让C#中的命令行交互举重若轻
在代码中进行命令行交互是一个很常见的场景, 特别是在一些CI CD 自动化流程中, 在这之前我们会使用 System.Diagnostics.Process API, 现在有一个更灵活的工具 CliW ...
- 巩固javaweb第十四天
巩固内容: 单行文本框: 单行文本框的基本语法格式如下: < input type="text" name="输入信息的字" value=" ...
- Go Robot
1 <html> 2 <meta http-equiv="Content-Type" content="text/html; charset=utf-8 ...
- Flink(六)【ParameterTool类】
ParameterTool 工具类 object ParameterToolTest { def main(args: Array[String]): Unit = { val params: Par ...
- Android中的性能优化
由于手机硬件的限制,内存和CPU都无法像pc一样具有超大的内存,Android手机上,过多的使用内存,会容易导致oom,过多的使用CPU资源,会导致手机卡顿,甚至导致anr.我主要是从一下几部分进行优 ...
- sonic 安装记录
https://github.com/valeriansaliou/sonic $ rustc --versionrustc 1.50.0-dev ubantu环境 rocksdb 安装依赖 apt ...
- SpringIOC原理浅析
1. IoC理论的背景我们都知道,在采用面向对象方法设计的软件系统中,它的底层实现都是由N个对象组成的,所有的对象通过彼此的合作,最终实现系统的业务逻辑. 图1:软件系统中耦合的对象 如果我们打开机械 ...
- MySQL(5):安装MySQL
下载地址 下载地址:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-winx64.zip 安装步骤 第一步:下载得到压缩包,并解压 ...
- 【Spring Framework】Spring入门教程(四)注册Bean到IOC容器
注册Bean到IOC容器大致分为4种: ①.包扫描+组件注解(@Controller.@Service.@Repository.@Component) 针对类是我们自己编写的情况 ②.@Bean注解 ...
- Jenkins凭证管理
目录 一.简介 二.管理凭证 三.常用凭证 保密文本 账号密码 保密文件 账号秘钥 四.优雅使用凭证 保密文本 账号密码 保密文件 五.凭证插件 集成HashiCorp Vault pipeline ...