题解:

看到区间修改先想一下差分

这题用差分是为了分析问题

现在的问题就变成了

原序列全为0,要使得特定的k个点变为1,每个操作改变x,y+1

然后我们会发现

对于二元组a,b我们要修改它,实际上是在找连续的区间相连,所以实质上是最短路

为什么要差分了才能这么做呢

因为原来的区间修改可能中间涉及了有效点而变得复杂

现在每次有效操作不会影响到中间的有效点

接下来状压dp这是显然的

对于每一个状态,枚举二元组(确定其中一个值,枚举另一个值)

这是因为被确定的这个值一定是其中一个二元组

在做这个之前,还需要证明的是三元组,4元组。。。是无效的

首先奇数是不可能的

看一下四元组,一定是可以拆分成两个无关的二元组

非常的智障的是我写最短路的时候只往一边走。。 应该要往两边扩展

#include <bits/stdc++.h>
using namespace std;
int T,n,m,k;
int len[],s[];
#define rg register
#define IL inline
#define N 10100
#define N2 1100000
#define INF 1e9
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
char ss[<<],*A=ss,*B=ss;
inline char gc(){return A==B&&(B=(A=ss)+fread(ss,,<<,stdin),A==B)?EOF:*A++;}
template<class T>void read(T&x){
rg int f=,c;while(c=gc(),c<||<c)if(c=='-')f=-;x=c^;
while(c=gc(),<c&&c<)x=(x<<)+(x<<)+(c^);x*=f;
}
bool ff[N],f[N];
queue<int> q;
int dis[][N],dp[N2];
int main()
{
freopen("noi.in","r",stdin);
freopen("noi.out","w",stdout);
std::ios::sync_with_stdio(false);
read(T);
for (rg int TT=;TT<=T;TT++)
{
memset(ff,,sizeof(ff));
int kk=;
read(n); read(m); read(k);
rg int x,y;
for (rg int i=;i<=m;i++)
read(x),ff[x]^=,ff[x+]^=;
for (rg int i=;i<=n+;i++)
if (ff[i]) s[++kk]=i;
for (rg int i=;i<=kk;i++)
for (rg int j=;j<=n+;j++)
dis[i][j]=INF;
for (rg int i=;i<=k;i++) read(len[i]);
for (rg int i=;i<N2;i++) dp[i]=INF;
for (rg int i=;i<=kk;i++)
{
memset(f,,sizeof(f));
q.push(s[i]); dis[i][s[i]]=;
while (!q.empty())
{
rg int x=q.front(); q.pop();
for (rg int j=;j<=k;j++)
if (x-len[j]>&&f[x-len[j]])
{
dis[i][x-len[j]]=dis[i][x]+;
f[x-len[j]]=;
q.push(x-len[j]);
}
for (rg int j=;j<=k;j++)
if (x+len[j]<=n+&&f[x+len[j]])
{
dis[i][x+len[j]]=dis[i][x]+;
f[x+len[j]]=;
q.push(x+len[j]);
}
}
}
/* for (int i=1;i<=kk;i++)
{
cout<<endl<<endl;
for (int j=1;j<=n;j++)
cout<<dis[i][j]<<" ";
} */
for (rg int i=;i<=kk;i++)
for (rg int j=;j<i;j++)
{
int x=(<<(i-))|(<<(j-));
dp[x]=dis[i][s[j]];
}
for (rg int i=;i<=(<<kk)-;i++)
{
rg int x;
for (rg int j=;j<kk;j++)
if ((i>>j)&)
{
x=j+; break;
}
for (rg int j=;j<kk;j++)
if ((i>>j)&&&j+!=x)
{
y=(<<j)|(<<(x-));
dp[i]=min(dp[i],dp[y]+dp[i^y]);
}
}
/* for (rg int i=1;i<=(1<<kk)-1;i++)
for (rg int j=i;j;j=i&(j-1))
{
for
dp[i]=min(dp[i],dp[j]+dp[i^j]);
} */
dp[(<<kk)-]==INF?cout<<-<<endl:cout<<dp[(<<kk)-]<<endl;
}
return ;
}

#12【BZOJ3003】LED BFS+状压DP的更多相关文章

  1. 【BZOJ3003】LED BFS+状压DP

    [BZOJ3003]LED Description LED屏是由一个庞大的点阵小灯泡组成的,一开始每个小灯泡都不发光.每一行一共有N个小灯泡,依次标号为1~n.现在给定K个点,要求这K个点发光,其余点 ...

  2. hdu 4856 Tunnels (bfs + 状压dp)

    题目链接 The input contains mutiple testcases. Please process till EOF.For each testcase, the first line ...

  3. HDU-4856 Tunnels (BFS+状压DP)

    Problem Description Bob is travelling in Xi’an. He finds many secret tunnels beneath the city. In hi ...

  4. 孤岛营救问题(BFS+状压DP)

    孤岛营救问题 https://www.luogu.org/problemnew/show/P4011 用状压DP标记拿到钥匙的数量 #include<iostream> #include& ...

  5. QDUOJ 来自xjy的签到题(bfs+状压dp)

    来自xjy的签到题   Description 爱丽丝冒险来到了红皇后一个n*n大小的花园,每个格子由'.'或'#'表示,'.'表示爱丽丝可以到达这个格子,‘#’表示爱丽丝不能到达这个格子,爱丽丝每1 ...

  6. HDU-3681-Prison Break(BFS+状压DP+二分)

    Problem Description Rompire is a robot kingdom and a lot of robots live there peacefully. But one da ...

  7. 【BZOJ 3049】【USACO2013 Jan】Island Travels BFS+状压DP

    这是今天下午的互测题,只得了60多分 分析一下错因: $dis[i][j]$只记录了相邻的两个岛屿之间的距离,我一开始以为可以,后来$charge$提醒我有可能会出现来回走的情况,而状压转移就一次,无 ...

  8. CodeForces 907E Party(bfs+状压DP)

    Arseny likes to organize parties and invite people to it. However, not only friends come to his part ...

  9. HDU 3247 Resource Archiver (AC自动机+BFS+状压DP)

    题意:给定 n 个文本串,m个病毒串,文本串重叠部分可以合并,但合并后不能含有病毒串,问所有文本串合并后最短多长. 析:先把所有的文本串和病毒都插入到AC自动机上,不过标记不一样,可以给病毒标记-1, ...

随机推荐

  1. python 小程序,替换文件中的字符串

    [root@PythonPC ~]# cat passwd root:x:::root:/root:/bin/bash bin:x:::bin:/bin:/sbin/nologin daemon:x: ...

  2. JAVA迭代器学习--在JAVA中实现线性表的迭代器

    1,迭代器是能够对数据结构如集合(ADT的实现)进行遍历的对象.在遍历过程中,可以查看.修改.添加以及删除元素,这是它与一般的采用循环来遍历集合中的元素不同的地方.因为,通常用循环进行的遍历操作一般是 ...

  3. Linux - 文件ACL权限控制

    getfacl 1.test # 查看文件ACL权限 setfacl -R -m u:xuesong:rw- 1.test # 对文件增加用户的读写权限 -R 递归

  4. 顺序列表(栈/队列等)ADT[C++]

    #include<iostream> using namespace std; //ADT template<class T> class SeqList{ public: / ...

  5. android studio 清空缓存插件

    http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/0308/4036.html 一个提高开发效率的ADB插件:ADB IDEA 泡在 ...

  6. pl/sql Devloper 关键字转为大写

    英文版: peferences-editor-keyword case -uppercase   中文版:

  7. SpringBoot整合Jest操作ES

    (1).添加依赖 <dependency> <groupId>io.searchbox</groupId> <artifactId>jest</a ...

  8. UML和模式应用4:初始阶段(2)--需求科目之进化式需求

    1. 前言 UP开发包括四个阶段:初始阶段.细化阶段.构建阶段.移交阶段: UP每个阶段包括 业务建模.需求.设计等科目: 需求是UP科目之一,在初始阶段需求科目的工作量占据较大的部分.但是初始阶段的 ...

  9. 使用Navicat Premium对mssql2008r2授权用户

    使用Navicat Premium操作mssql2008r2数据库 比如需要对某个特定的数据tes添加一个管理员em,并且这个管理员只能对test这个数据库进行操作 使用sa连接数据库 1.新建一个登 ...

  10. nginx访问报错403 is forbidden

    由于开发需要,在本地环境中配置了nginx环境,使用的是Centos 6.5 的yum安装,安装一切正常,于是把网站文件用mv命令移动到了新的目录,并相应修改了配置文件,并重启Nginx. 重启就报个 ...