loj 1037(状压dp)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25914
思路:dp[state]表示当前状态下要消耗的最小的shots。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define inf 1<<30 int n,val[],dp[<<];
char map[][]; int main()
{
int _case,t=;
scanf("%d",&_case);
while(_case--){
scanf("%d",&n);
for(int i=;i<n;i++)scanf("%d",&val[i]);
for(int i=;i<n;i++)scanf("%s",map[i]);
fill(dp,dp+(<<n),inf);
for(int i=;i<n;i++)dp[<<i]=val[i];
for(int state=;state<(<<n);state++){
if(dp[state]==inf)continue;
for(int i=;i<n;i++)if(state&(<<i)){
for(int j=;j<n;j++)if(!(state&(<<j))){
int cnt=map[i][j]-'';
if(cnt==)dp[state|(<<j)]=min(dp[state|(<<j)],dp[state]+val[j]);
else {
cnt=val[j]/cnt+(val[j]%cnt!=);
dp[state|(<<j)]=min(dp[state|(<<j)],dp[state]+cnt);
}
}
}
}
printf("Case %d: %d\n",t++,dp[(<<n)-]);
}
return ;
}
loj 1037(状压dp)的更多相关文章
- loj 1021(状压dp+记忆化搜索)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25887 题目大意:给定的一个某进制下的排列,问它的全排列有多少个能 ...
- loj 1018(状压dp+记忆化搜索)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25844 思路:首先预处理出点在同一直线上的所有的点集状态(dp[i ...
- light oj 1037 状压dp
#include <iostream> #include <cstdlib> #include <cstring> #include <queue> # ...
- Loj 6433. 「PKUSC2018」最大前缀和 (状压dp)
题面 Loj 题解 感觉挺难的啊- 状压\(dp\) 首先,有一个性质 对于一个序列的最大前缀和\(\sum_{i=1}^{p} A[i]\) 显然对于每个\(\sum_{i=p+1}^{x}A[i] ...
- lightoj 1037 - Agent 47(状压dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1037 #include <iostream> #include & ...
- loj 1316(spfa预处理+状压dp)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27024 题意:求0-(n-1)的经过最多的标记的点的最短路. 思路 ...
- loj#10172 涂抹果酱 (状压DP)
题目: #10172. 「一本通 5.4 练习 1」涂抹果酱 解析: 三进制的状压DP 经过简单的打表发现,在\(m=5\)时最多有\(48\)种合法状态 然后就向二进制一样枚举当前状态和上一层的状态 ...
- loj #6177. 「美团 CodeM 初赛 Round B」送外卖2 状压dp floyd
LINK:#6177.美团 送外卖2 一道比较传统的状压dp题目. 完成任务 需要知道自己在哪 已经完成的任务集合 自己已经接到的任务集合. 考虑这个dp记录什么 由于存在时间的限制 考虑记录最短时间 ...
- BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3336 Solved: 1936[Submit][ ...
随机推荐
- 【leetcode】Valid Number
Valid Number Validate if a given string is numeric. Some examples:"0" => true" 0.1 ...
- oracle数据库迁移---windows环境下
以前在学校只是听过oracle,但是从来没有接触过.最近公司突然给了我一个任务,让我将某个大型商场的网站迁移到与服务器上面. 当时也觉得,迁移个网站也就是个很简单的事情,将文件复制,拷贝下就可以了撒. ...
- Selenium 模拟人输入
public static void type(WebElement e,String str) throws InterruptedException { String[] singleCharac ...
- UVALive 6577 Binary Tree 二叉树的LRU串
今天继续攒人品...真开心啊O(∩_∩)O~~各种身体不舒服~~ https://icpcarchive.ecs.baylor.edu/external/65/6577.pdf 题意是这样的,现在有一 ...
- C++基础(纯虚函数与抽象类)
C++基础之纯虚函数与抽象类 引言 纯虚函数在C++编程中的地位很重要,其关联到了设计模式中"接口"的概念. 语法 纯虚函数的语法: 1. 将成员函数声明为virtual 2. ...
- 【leetcode】triangle(easy)
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- 【python】 urllib.unquote()
来源:http://blog.csdn.net/anhuidelinger/article/details/10096727 urllib.unquote() 字符串被当作url提交时会被自动进行ur ...
- curl命令 抓取网络数据相应头
curl --verbose --data "Password=123&Username=158101068&url=http://m.vancl.com/" & ...
- android setCompoundDrawables 不显示问题
在 vh.tvAddr.setCompoundDrawables(getResources().getDrawable(R.drawable.ic_real_state_loc), null, nul ...
- jpg Test