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, Accepted : 34
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.
Problem
Individual jobs are numbered 1 through n. Given the base price p for each job and a surcharge s (in US)foreverypairofjobs(i,j)withi!=j,meaningthatyouhavetopayadditionals 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
The first line contains the number of scenarios. For each scenario, an integer number of jobs n, 1 <= n <= 14, is given. Then follow n lines, each containing exactly n integers. The i-th line contains the surcharges that have to be paid in garage number i for the i-th job and the base price for job i. More precisely, on the i-th line, the i-th integer is the base price for job i and the j-th integer (j != i) 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
The output for every scenario begins with a line containing “Scenario #i:”, where i is the number of the scenario starting at 1. Then print a single line: “You have officially been pimped for only p” with p being the minimum total price. Terminate the output for the scenario with a blank line.
Sample Input
2
2
10 10
9000 10
3
14 23 0
0 14 0
1000 9500 14
Sample Output
Scenario #1:
You have officially been pimped for only30
Scenario #2:
You have officially been pimped for only $42
注意题目:每次做一个job都要把之前做过的所有job额外的费用加上
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
#define MAX 100000000
int dp[1<<15][15];
int a[15][15];
int ans;
int n;
int main()
{
int t;
scanf("%d",&t);
int cas=0;
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
int state=(1<<n)-1;
for(int i=0;i<=state;i++)
for(int j=0;j<n;j++)
dp[i][j]=MAX;
for(int i=0;i<n;i++)
dp[1<<i][i]=a[i][i];
for(int i=1;i<=state;i++)
{
for(int j=0;j<n;j++)
{
if((1<<j)&i)
{
int num=a[j][j];
for(int k=0;k<n;k++)
{
if(k!=j&&((1<<k)&i))
num+=a[j][k];
}
for(int p=0;p<n;p++)
{
if(p!=j&&((1<<p)&i))
dp[i][j]=min(dp[i][j],num+dp[i-(1<<j)][p]);
}
}
}
}
ans=MAX;
for(int i=0;i<n;i++)
ans=min(ans,dp[state][i]);
printf("Scenario #%d:\n",++cas);
printf("You have officially been pimped for only $%d\n\n",ans);
}
return 0;
}
HOJ 2317 Pimp My Ride(状态压缩DP)的更多相关文章
- HOJ 2226&POJ2688 Cleaning Robot(BFS+TSP(状态压缩DP))
Cleaning Robot Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4264 Accepted: 1713 Descri ...
- 学习笔记:状态压缩DP
我们知道,用DP解决一个问题的时候很重要的一环就是状态的表示,一般来说,一个数组即可保存状态.但是有这样的一些题 目,它们具有DP问题的特性,但是状态中所包含的信息过多,如果要用数组来保存状态的话需要 ...
- hoj2662 状态压缩dp
Pieces Assignment My Tags (Edit) Source : zhouguyue Time limit : 1 sec Memory limit : 64 M S ...
- POJ 3254 Corn Fields(状态压缩DP)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4739 Accepted: 2506 Descr ...
- [知识点]状态压缩DP
// 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...
- HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP
题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...
- DP大作战—状态压缩dp
题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...
- 状态压缩dp问题
问题:Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Ev ...
- BZOJ-1226 学校食堂Dining 状态压缩DP
1226: [SDOI2009]学校食堂Dining Time Limit: 10 Sec Memory Limit: 259 MB Submit: 588 Solved: 360 [Submit][ ...
随机推荐
- nodejs基础 -- 事件循环
Node.js 事件循环 Node.js 是单进程单线程应用程序,但是通过事件和回调支持并发,所以性能非常高. Node.js 的每一个 API 都是异步的,并作为一个独立线程运行,使用异步函数调用, ...
- par函数的xaxt函数-控制x轴刻度的显示
xaxt 参数控制x轴的刻度以及刻度对应的标签时候显示 默认值为‘s’, 表示显示,代码示例 par(xaxt = 's') plot(1:5, 1:5, main = "title&quo ...
- 使用avahi 的mdns服务发现server
avahi-browse -a 可以查看局域网内所有的mdns服务, avahi-browse -r _xxxxx._tcp
- 刚刚完成了在vs2013中通过 ef连接mysql数据库的工作。感觉没有想象中的简单。试了n次终于成功。故记录成功的方法,希望可以帮到大家
分两种情况,如果你是用entity framework 5.0的时候 mysql-connector-net的版本不是很重要. MySQL For VisualStudio的版本也不重要 (这个不装就 ...
- There are inconsistent line endings in the 'xxx' script. Some are Mac OS X (UNIX) and some are Windows.问题解决
在Window上使用Visual Studio编辑Unity3D脚本时常会出现类似如下警告: 警告 1 There are inconsistent line endings in the 'Asse ...
- 记录下一个自己不常用的关键字-yield
yield 这个关键字 一直很少用,也不知道具体用途.按照习惯就查询了下MSDN. 意思大致是这样的:在迭代器块中用于向枚举数对象提供值或发出迭代结束信号 表现形式:1. yield return & ...
- PHPCMS v9在后台文章管理列表添加类别
进入PHPCMS v9后台—内容,进入PHPCMS的文章管理列表,要实现在文章标题前显示文章类别,就是可以直接在文章列表里看到类别,不需要点击进入编辑页面才可以看到,如下图: PHPCMS v9在后台 ...
- 服务器允许js跨域
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Methods:POST,GET'); header('Ac ...
- docker学习之-什么是docker
docker是一个用来装应用的容器,就想杯子可以装水,笔筒可以装笔,书包可以放书一样,可以把网站放到docker里,可以把任何应用放到docker里.
- cocos2d-x游戏引擎核心之六——绘图原理和绘图技巧
一.OpenGL基础 游戏引擎是对底层绘图接口的包装,Cocos2d-x 也一样,它是对不同平台下 OpenGL 的包装.OpenGL 全称为 Open Graphics Library,是一个开放的 ...