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 状态压缩]
题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数 ...
随机推荐
- LINQ 多条件写法
源代码: string depAll = (ddl_dep1.SelectedValue == "") ? "" : ddl_dep1.SelectedValu ...
- [转载]Oracle基础知识
一.oracle安装过程略 二.sys用户和system用户 (1)sys用户是超级用户,具有最高权限,具有sysdba角色,有create database的权限 默认密码是change_onins ...
- PL/SQL常见设置--Kevin的专栏
body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...
- ios专题 - socket(1)
二,BSD socket API 简介 BSD socket API 和 winsock API 接口大体差不多,下面将列出比较常用的 API: API接口 讲解 int socket(int add ...
- Lucene索引的初步创建
从百度上知道的,Lucene是apache软件基金会4 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,但它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的 ...
- 【HDU1402】【FNT版】A * B Problem Plus
Problem Description Calculate A * B. Input Each line will contain two integers A and B. Process to ...
- MySQL常用函数 转载
一.数学函数ABS(x) 返回x的绝对值BIN(x) 返回x的二进制(OCT返回八进制,HEX返回十六进制)CEILING(x) 返 ...
- AS3.0声明静态属性和静态方法
静态属性的变量声明要加static,static var 名称:属性类型=值 静态属性的常量声明要加static或者const,并在声明时就要赋值.static||const var 名称:属性类型= ...
- bzoj 1500: [NOI2005]维修数列 splay
1500: [NOI2005]维修数列 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 6556 Solved: 1963[Submit][Status ...
- ExecutorService介绍
转自: http://victorzhzh.iteye.com/blog/1010359 下面是excutor相关的类结果: ExecutorService接口继承了Executor接口,定义了一些生 ...