#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. js 当前时间和对比时间的比较

    <!DOCTYPE><html> <head> <meta charset="utf-8" /> <title>功能:当 ...

  2. CF377D Developing Game

    题目链接: luogu 题目分析: 把每个人当成一个三元组\([l_i, r_i, v_i]\) 考虑每个人对哪个能力区间\([L, R]\)有贡献 应该是左端点在\([l_i, v_i]\),右端点 ...

  3. 修改Chrome的UserAgent

    修改Chrome的UserAgent 直接在chrome商店中搜索user-agent switcher 打开chrome 商店,搜索 user-agent switcher   点击免费, 然后执行 ...

  4. hexo next主题中遇到的关于require的timeout的问题。Uncaught Error: Load timeout for modules:

    个人博客:https://mmmmmm.me 源码:https://github.com/dataiyangu/dataiyangu.github.io 背景 报错:Uncaught Error: L ...

  5. where与having区别

    解释一. 聚合函数是比较where.having 的关键. 开门见山.where.聚合函数.having 在from后面的执行顺序: where>聚合函数(sum,min,max,avg,cou ...

  6. Minifilter 相关

    FLTFL_OPERATION_REGISTRATION_SKIP_PAGING_IO 商用软件一定要过滤掉这个类型的请求,这个类型的请求响应非常慢. FLTFL_OPERATION_REGISTRA ...

  7. 2019-8-30-PowerShell-通过-WMI-获取系统安装的驱动

    title author date CreateTime categories PowerShell 通过 WMI 获取系统安装的驱动 lindexi 2019-08-30 08:58:39 +080 ...

  8. Aria2配置文件-aria2.conf

    ##此部分主要分为几部分###1.文件保存#2.下载链接#3.进度保存#4.RPC相关#5.BT\PT下载相关 ##===================================#### 文件 ...

  9. Data Dependency

    https://en.wikipedia.org/wiki/Data_dependency (There’s some misleading expression on the flow/data d ...

  10. Windows相关命令

    1.查看端口8080被哪个进程占用 netstat -ano | findstr "8080" 2.查看进程号为5768对应的进程 tasklist | findstr " ...