CF - 1117 F Crisp String
题解:
枚举非法对。
如果 ‘a' 和 ’b' 不能相邻的话,那么删除 'a' 'b'之间的字符就是非法操作了。 假设题目给定的字符串为 "acdbe",所以删除cd是非法操作, 因为cd是非法了,所以cde也是非法操作,
也就是说找到所有的非法操作之后往外推,比他多删的状态就一样是非法的了,当然对于上述的“acdbe"来说,不能确定 ”acd"是非法操作,因为在枚举非法对的时候,该非法对的字符并不能被删除。
然后把所有非法对的非法状态都存下来。然后从没删除的状态往外搜,就好了。
代码:
/*
code by: zstu wxk
time: 2019/03/06
Problem Link: http://codeforces.com/contest/1117/problem/F
Solve:
*/
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
char s[N];
int a[][], cnt[];
int tmp[<<], gg[<<];
int n, m, k;
void solve(int u, int v){
memset(tmp, , sizeof(tmp));
for(int i = , j; i <= n;){
while(i <= n && s[i]-'a' != u) ++i;
int t = ;
j = i+;
while(j <= n && s[j] -'a' != u && s[j]-'a' != v) {
t |= << s[j]-'a';
++j;
}
if(j > n) break;
if(s[j] - 'a' == v){
i = j+;
tmp[t] = ;
}
if(s[j] - 'a' == u)
i = j;
}
for(int i = ; i <= k; ++i){
if(tmp[i]){
gg[i] = ;
for(int j = ; j < m; ++j){
if(j == u || j == v) continue;
tmp[i|(<<j)] = ;
}
}
}
return ;
}
int vis[<<];
int ans;
void DFS(int x, int len){
if(vis[x]) return ;
vis[x] = ;
ans = min(ans, len);
for(int i = ; i < m; ++i){
if(gg[x | (<<i)]) continue;
DFS(x|<<i, len-cnt[i]);
}
return ;
} void Ac(){
memset(gg, , sizeof(gg));
memset(cnt, , sizeof cnt);
scanf("%s", s+);
for(int i = ; i < m; ++i)
for(int j = ; j < m; ++j)
scanf("%d", &a[i][j]);
k = (<<m) - ;
for(int i = ; i < m; ++i)
for(int j = ; j < m; ++j)
if(a[i][j] == )
solve(i,j);
for(int i = ; i <= n; ++i){
cnt[s[i]-'a']++;
}
ans = n;
DFS(, n);
printf("%d\n", ans);
return ;
}
int main(){
while(~scanf("%d%d", &n, &m)){
Ac();
}
return ;
}
CF - 1117 F Crisp String的更多相关文章
- CF 628C --- Bear and String Distance --- 简单贪心
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...
- CF 633 F. The Chocolate Spree 树形dp
题目链接 CF 633 F. The Chocolate Spree 题解 维护子数答案 子数直径 子数最远点 单子数最长直径 (最长的 最远点+一条链) 讨论转移 代码 #include<ve ...
- CF 1117 E. Decypher the String
E. Decypher the String 链接 题意: 有一个字符串,一些操作,每次操作交换两个位置的字符,经过这些操作后,会得到新的字符串.给你新的字符串,求原来的串.可以有3次询问,每次询问给 ...
- CF #271 F Ant colony 树
题目链接:http://codeforces.com/contest/474/problem/F 一个数组,每一次询问一个区间中有多少个数字可以整除其他所有区间内的数字. 能够整除其他所有数字的数一定 ...
- Crisp String CodeForces - 1117F (状压)
#include <iostream> #include <algorithm> #include <cstdio> #include <math.h> ...
- CF 494 F. Abbreviation(动态规划)
题目链接:[http://codeforces.com/contest/1003/problem/F] 题意:给出一个n字符串,这些字符串按顺序组成一个文本,字符串之间用空格隔开,文本的大小是字母+空 ...
- Codeforces - 1117E - Crisp String - 进制 - 交互
https://codeforces.com/problemset/problem/1117/E 就用abc表示数字来给每个数编码,编完直接问出移动的结果,反构造就行了,比C和D还简单. #inclu ...
- cf 864 F. Cities Excursions
F. Cities Excursions There are n cities in Berland. Some pairs of them are connected with m directed ...
- Codeforces Round #582 (Div. 3) F. Unstable String Sort
传送门 题意: 你需要输出一个长度为n的字符序列(由小写字母组成),且这个字符串中至少包含k个不同的字符.另外题目还有要求:给你两个长度为p和q的序列,设字符序列存在s中 那么就会有s[Pi]< ...
随机推荐
- 【JDK】JDK源码分析-AbstractQueuedSynchronizer(2)
概述 前文「JDK源码分析-AbstractQueuedSynchronizer(1)」初步分析了 AQS,其中提到了 Node 节点的「独占模式」和「共享模式」,其实 AQS 也主要是围绕对这两种模 ...
- Thinkphp5.0快速入门笔记(2)
学习来源与说明 https://www.kancloud.cn/thinkphp/thinkphp5_quickstart 测试与部署均在windows10下进行学习. 示例建立新的模块和控制器 在a ...
- Zabbix编译安装(全)
一.前言 (一).概述 Zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案,Zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系 ...
- UR机器人通信--上位机通信(python)
一.通信socket socket()函数 Python 中,我们用 socket()函数来创建套接字,语法格式如下: socket.socket([family[, type[, proto]]]) ...
- 2019牛客多校训练第三场H.Magic Line(思维)
题目传送门 大致题意: 输入测试用例个数T,输入点的个数n(n为偶数),再分别输入n个不同的点的坐标,要求输出四个整数x1,y1,x2,y2,表示有一条经过点(x1,y1),(x2,y2)的直线将该二 ...
- Java 复制PDF文档的2种方法
本文将介绍通过Java程序来复制PDF页面,包括: 跨文档复制,即从文档1复制到文档2 在同一文档内复制,即从页面A复制到页面B 使用工具:Free Spire.PDF for Java (免费版) ...
- 洛谷 P2152 [SDOI2009]SuperGCD
题意简述 求两个整数a,b的最大公约数0 < a , b ≤ 10 ^ 10000. 题解思路 如果 a % 2 == 0 && b % 2 == 0 gcd(a,b) = gc ...
- Unity进阶之ET网络游戏开发框架 01-下载、运行
版权申明: 本文原创首发于以下网站: 博客园『优梦创客』的空间:https://www.cnblogs.com/raymondking123 优梦创客的官方博客:https://91make.top ...
- P3195 [HNOI2008]玩具装箱TOY 斜率优化dp
传送门:https://www.luogu.org/problem/P3195 题目描述 P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任 ...
- DNS主、从域名服务器配置
#命令为红色 #vi编辑内容为蓝色 建立主.从或者缓存域名服务器,前提一定要关闭防火墙和linux防护机制,否则不能成功解析客户机请求 永久关闭防火墙和安全机制命令如下: systemctl stop ...