#include <iostream>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <cstdio>
#include <algorithm>
#include <map>
//#include <time.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define LL long long using namespace std;
//using namespace __gnu_pbds; int dp[<<]; int attack[][],health[]; int n; int check(int j,int i)
{
int a = ;
a = max(a,attack[j][i]);
return (health[i]/a) + (health[i]%a?:);
} int dfs(int statu)
{
if(dp[statu] != -)
return dp[statu];
dp[statu] = 0x3f3f3f3f;
if(statu == )
return dp[statu] = ;
for(int i = ; i <= n; i++)
{
if( ((statu>>(i-))&) == )
continue;
dp[statu] = min(dp[statu],dfs( (statu^(<<(i-))))+health[i]/);
for(int j = ; j <= n; j++)
{
if(i == j) continue; if( ((statu>>(j-))&) == )
{
dp[statu] = min(dp[statu],dfs( (statu^(<<(i-)) )) + check(j,i) );
}
} } return dp[statu];
} void solve()
{
memset(dp,-,sizeof(dp)); scanf("%d",&n);
for(int i = ; i <= n; i++)
scanf("%d",&health[i]);
for(int i = ; i <= n; i++)
for(int j = ; j <= n; j++)
scanf("%1d",&attack[i][j]); int ans = dfs( (<<n)-); printf("%d\n",ans);
} int main(void)
{
int t,cnt = ;
scanf("%d",&t);
while(t--)
{
printf("Case %d: ",++cnt);
solve();
}
return ;
}

light oj 1037 状压dp的更多相关文章

  1. light oj 1057 状压dp TSP

    #include <iostream> #include <cstdlib> #include <cstring> #include <queue> # ...

  2. loj 1037(状压dp)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25914 思路:dp[state]表示当前状态下要消耗的最小的sho ...

  3. Light OJ 1011 - Marriage Ceremonies(状压DP)

    题目大意: 有N个男人,和N个女人要互相匹配,每个男人和每个女人有个匹配值. 并且匹配只能是1对1的. 问所有人都匹配完成,最大的匹配值是多少?   状压DP,暴力枚举就OK了, 这个题目略坑,因为他 ...

  4. 江南OJ 1151 - 还是晒太阳 - [状压DP]

    题目链接:校内OJ的题目,就不放链接了. PS.可以说是本次9月月赛唯一的一道有一定难度的题目了. 题解: 考虑状压DP,假设 $sta$ 是一个二进制数,代表当前 $n$ 个人有几个是在队伍里的,剩 ...

  5. lightoj 1037 - Agent 47(状压dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1037 #include <iostream> #include & ...

  6. 2018.08.29 NOIP模拟 movie(状压dp/随机化贪心)

    [描述] 小石头喜欢看电影,选择有 N 部电影可供选择,每一部电影会在一天的不同时段播 放.他希望连续看 L 分钟的电影.因为电影院是他家开的,所以他可以在一部电影播放过程中任何时间进入或退出,当然他 ...

  7. Educational Codeforces Round 13 E. Another Sith Tournament 状压dp

    E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...

  8. bjtu 1846. Infinity的装备[状压dp+dfs/bfs]

    https://citel.bjtu.edu.cn/acm/oj/problem/1846 1846. Infinity的装备 时间限制 1000 ms 内存限制 64 MB 题目描述 “测试服终于下 ...

  9. 算法复习——状压dp

    状压dp的核心在于,当我们不能通过表现单一的对象的状态来达到dp的最优子结构和无后效性原则时,我们可能保存多个元素的有关信息··这时候利用2进制的01来表示每个元素相关状态并将其压缩成2进制数就可以达 ...

随机推荐

  1. 最大流拆点——hdu2732,poj3436

    一种很普遍的做法就是把一个带有容量的点拆成两个点,一个入点一个出点,链接两个点的边的权值为这个点的容量 hdu3732 #include<cstdio> #include<cstri ...

  2. python相关软件安装流程图解——虚拟机安装——CentOS-7-x86_64-DVD-1810——CentOS-01下载——CentOS-02安装——CentOS-03配置操作

    http://www.xitongzhijia.net/soft/24315.html http://www.downxia.com/downinfo/4574.html     .

  3. Linux课程---15、域名相关

    Linux课程---15.域名相关 一.总结 一句话总结: 先购买域名,再备案,再解析,域名即可使用 1.域名备案是怎么回事(比如二级域名,三级域名)? 每个二级域名需要备案一次,三级域名不需要备案, ...

  4. Windbg 查看SSDT表

    SSDT HOOK 的原理其实非常简单,我们先实际看看KeServiceDescriptorTable是什么样的.         lkd> dd KeServiceDescriptorTabl ...

  5. Mybatis笔记 – insert语句中主键的返回

    在DBMS中可以使用insert语句显示指定自增主键值,但Mybatis中不可,即使指定了也无效,可以使用特殊的方式返回主键. 一.自增主键返回         mysql自增主键执行insert提交 ...

  6. CSS 常用的兼容性调试技巧

    1.实现所有浏览器主页居中 Firefox下主页居中代码:.box{margin:0px auto} IE5.5下主页居中代码:body{text-align:center;} 将以上两种代码,合在一 ...

  7. PAT甲级——A1138 Postorder Traversa【25】

    Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and in ...

  8. 最近开始学习python,学习到了关于web的内容。

    然而在win10中IIS发布CGI脚本的时候遇到了各种各样的问题. 如ISAPI和CGI限制,权限限制等等,一一的百度解决了,最后又出现了 HTTP 错误 502.2 - Bad Gateway Th ...

  9. <数据可视化>样例+数据+画图

    1 样例 1.1样例1 子图系列 from pylab import * def f(x): return np.exp(-x) * np.cos(2*np.pi*x) x1 = np.arange( ...

  10. <day001>存储到Mysql、mongoDB数据库+简单的Ajax请求+os模块+进程池+MD5

    任务1:记住如何存储到Mysql.mongoDB数据库 ''' 存储到Mysql ''' import pymysql.cursors class QuotePipeline(object): def ...