lightoj 1037 状态压缩
题目链接:http://lightoj.com/volume_showproblem.php?problem=1037
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn = <<;
const int INF = 0x3f3f3f3f; int dp[maxn]; //dp[S]代表杀死集合S中的人需要的最小shot数。
char s[][];
int Hel[];
int N; int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
int T;
cin>>T;
for(int cas=; cas<=T; cas++)
{
cin>>N;
for(int i=; i<N; i++)
scanf("%d",&Hel[i]); for(int i=; i<N; i++)
scanf("%s",s[i]); memset(dp,0x3f,sizeof(dp));
int All = (<<N)-;
for(int i=; i<N; i++)
dp[<<i] = Hel[i]; for(int S=; S<=All; S++)
{
for(int i=; i<N; i++)
{
if(!(<<i&S)) continue;
for(int j=; j<N; j++)
{
if(((<<j)&S) || i==j) continue; if(s[i][j] == '')
{
dp[S|<<j] = min(dp[S|<<j],dp[S] + Hel[j]);
continue;
}
int num = s[i][j] - '';
int add = Hel[j]/num;
if(Hel[j]%num>) add++;
dp[S|<<j] = min(dp[S|<<j],dp[S] + add);
}
}
}
printf("Case %d: %d\n",cas,dp[All]);
}
}
lightoj 1037 状态压缩的更多相关文章
- lightoj 1011 (状态压缩dp)
思路:状态压缩dp,设dp[i][j] 表示前i行,状态为j时的最大值,状态定义为:若前i行中取了第x列那么j的二进制位中第x位为1,否则为0,最后答案就是dp[n-1][(1 << n) ...
- loj1011 状态压缩
题目链接:http://lightoj.com/volume_showproblem.php?problem=1011 思路:最近的开始做dp了...很明显的一道状态压缩题,dp[n][state]表 ...
- Marriage Ceremonies(状态压缩dp)
Marriage Ceremonies Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- HDU 3605:Escape(最大流+状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...
- [HDU 4336] Card Collector (状态压缩概率dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...
- HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)
题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...
- codeforces B - Preparing Olympiad(dfs或者状态压缩枚举)
B. Preparing Olympiad You have n problems. You have estimated the difficulty of the i-th one as inte ...
- NOIP2005过河[DP 状态压缩]
题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数 ...
随机推荐
- FTPClient文件下载
一.FTPClient下载文件所需要的jar包: org.apache.commons.net [commons-net-3.4.jar] 二.FTPClient的连接和关闭 //FTPClient ...
- CI 自动操作日志
在控制器中,继承一个总控制器,MY_Controller,让其他集成的控制器,继承my控制器 在MY_Controller控制器中,重写构造方法, 代码如下,测试pass! class MY_Cont ...
- (五)Struts2 标签
所有的学习我们必须先搭建好Struts2的环境(1.导入对应的jar包,2.web.xml,3.struts.xml) 第一节:Struts2 标签简介 Struts2 自己封装了一套标签,比JSTL ...
- ios 将状态栏改为白色方法!
1在Info.plist中设置UIViewControllerBasedStatusBarAppearance 为NO2 在需要改变状态栏颜色的ViewController中在ViewDidLoad方 ...
- 6 关于 Oracle NULL栏位和PL./SQL执行实验
今日有针对NULL值有了相关实验. 对NULL 值插入的讨论. 1, PL/SQL 中可以执行插入''或者NULL 的操作, 前提是栏位允许为空. 2, 可以对NULL进行一系列数据库运算. 如: ...
- VS番茄助手安装(vs2015+vs2010):卸载之前的vs助手再安装新版本
1 卸载之前的vs助手 vs2010: vs2015: 2 安装新版本
- getting “fatal: not a git repository: '.'” when using post-update hook to execute 'git pull' on another repo
Here is the script that ultimately worked. I think the bit I was originally missing that prevented i ...
- 深入了解jquery中的键盘事件
很多时候,我们需要获取用户的键盘事件,下面就一起来看看jquery是如何操作键盘事件的. 一.首先需要知道的是: 1.keydown() keydown事件会在键盘按下时触发. 2.keyup() k ...
- div模块变灰
整站变灰目前没发现什么特别好的办法,但是div(或者其他标签模块)模块变灰方法兼容性还不错. .gay_box{ filter: grayscale(100%); -webkit-filter: gr ...
- excel快递单号查询工具以及源码
Function kdcx(kd, orderid) Dim Err, url, kdtime, link, Errcode, Status Select Case kd '此处支持的快递公司很多的 ...