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][ ...
随机推荐
- DOM编程 学习笔记(二)
学习内容: 1.document对象 2.event对象 该对象将标记型文档进行封装 该对象的作用,是对可标记型文档进行操作 常见操作,想要实现动态效果,需要对节点操作,那么先获取到这个节点,想获取节 ...
- 基于bootstrap的Dialog
function yms_Dialog(container_id, modal_path, handle_function) { /// <summary> /// ...
- asp.net mvc清空指定cookies
HttpCookie hc = Request.Cookies["user"]; hc.Expires = DateTime.Now.AddDays( ...
- pcduino 无法打开usb摄像头。
1.sudo ./demon http://www.oschina.net/question/994181_118098 2.usb camera interfarce switch :http: ...
- codeforces 547A Mike and Frog
近期都是这样的题呢. . .... 哎 開始想纯暴力(体如今跳出循环t>=那里.,,,)..,.随着数据变大.. ...(t=499981500166是能够的),,,..,,23333333 超 ...
- python使用sqlalchemy连接pymysql数据库
python使用sqlalchemy连接mysql数据库 字数833 阅读461 评论0 喜欢1 sqlalchemy是python当中比较出名的orm程序. 什么是orm? orm英文全称objec ...
- impala不能查询hive中新增加的表问题
使用Cloudera Manager部署安装的CDH和Impala,Hive中新增加的表,impala中查询不到,其原因是/etc/impala/conf下面没有hadoop和hive相关的 ...
- Unity中SendMessage和Delegate效率比较
网上直接搜的代码.需要的使用也简单,所以就不过多说明. 但是网上都说,他们之间的差距,delegate比较快,效果高.怎么个高法呢?还是自己来测试下时间. 故此, 个人之用来比较下时间差别. 一.直接 ...
- php检测文件只读、可写、可执行权限
例子:检测文件是否可读.可写.可执行. 复制代码代码示例: <?php $myfile = "./test.txt"; if (is_readable ($myfile)) ...
- Visual Studio 2013 如何在停止调试Web程序后阻止IIS Express关闭
vs2013 调试项目的时候,当停止调试的时候,端口就被断了.之前以为是IIS那边的控制问题,但是其他并行的项目运行都没有出现这种情况. 最初也没在意,直到现在实在忍受不了了,每次重开也太烦了.就去各 ...