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命令行: ...
随机推荐
- Qemu/kvm虚拟化源码解析学习视频资料
地址链接:tao宝搜索:Linux云计算KVM Qemu虚拟化视频源码讲解+实践https://item.taobao.com/item.htm?ft=t&id=646300730262 L ...
- 学习java的第二十六天
一.今日收获 1.java完全学习手册第三章算法的3.2排序,比较了跟c语言排序上的不同 2.观看哔哩哔哩上的教学视频 二.今日问题 1.快速排序法的运行调试多次 2.哔哩哔哩教学视频的一些术语不太理 ...
- day09搭建均衡负载和搭建BBS博客系统
day09搭建均衡负载和搭建BBS博客系统 搭建BBS博客系统 本次搭建bbs用到的技术 需要用到的: 1.Nginx+Django 2.Django+MySQL 环境准备 主机 IP 身份 db01 ...
- python 从ubantu环境迁移到windows环境
下载安装Anaconda3 Anaconda3-2021.05-Windows-x86_64.exe 默认安装目录 C:\ProgramData\Anaconda3 可以启动Anaconda查看不同的 ...
- 记录一下使用MySQL的left join时,遇到的坑
# 现象 left join在我们使用mysql查询的过程中可谓非常常见,比如博客里一篇文章有多少条评论.商城里一个货物有多少评论.一条评论有多少个赞等等.但是由于对join.on.where等关键字 ...
- mysql index 8.0
创建表 use vodb; drop table if exists test1; create table test1(id int NOT NULL AUTO_INCREMENT primary ...
- oracle(查询数据库对象1)
1 --查询表信息 2 xxx_tables--包含表的基本描述信息和统计信息 3 xxx_tab_columns--包含表中列的描述信息和统计信息 4 xxx_all_tables--包含当前数据库 ...
- LVS nat模型+dr模型
nat模型 在 rs1 和 rs2 安装httpd 并配置测试页,启动 [root@rs1 ~]# yum install httpd -y[root@rs1 ~]# echo "thi ...
- 远程连接mysql库问题
如果你想连接你的mysql的时候发生这个错误: ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL serve ...
- 2.VUEJS-安装
Vue.js 安装 1.独立版本 我们可以在 Vue.js 的官网上直接下载 vue.min.js 并用 <script> 标签引入. 2.使用 CDN 方法 以下推荐国外比较稳定的两个 ...