AGC 026 C - String Coloring
比较简单的折半搜索,推一下hash函数,要求正反最后相等就行了。
#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std; unordered_map<ll,ll> mmp[23];
ll c[37],ans;
bool v[77];
char s[77];
int n,num; inline ll G(char x){ return x-'a'+3;} inline void update(){
ll z=0,f=0;
num=0; for(int i=n;i;i--) if(v[i]) f=f+G(s[i])*c[num++];
num=0; for(int i=1;i<=n;i++) if(!v[i]) z=z+G(s[i])*c[num++];
mmp[num][z-f*c[num]]++;
} inline void calc(){
ll z=0,f=0;
num=0; for(int i=2*n;i>n;i--) if(v[i]) f=f+G(s[i])*c[num++];
num=0; for(int i=n+1;i<=n*2;i++) if(!v[i]) z=z+G(s[i])*c[num++];
ans+=mmp[n-num][f-z*c[n-num]];
} void dfs1(int L){
if(L==n){ update(); return;}
dfs1(L+1),v[L+1]=1,dfs1(L+1),v[L+1]=0;
} void dfs2(int L){
if(L==n*2){ calc(); return;}
dfs2(L+1),v[L+1]=1,dfs2(L+1),v[L+1]=0;
} int main(){
scanf("%d",&n),scanf("%s",s+1);
c[0]=1; for(int i=1;i<=n;i++) c[i]=c[i-1]*233ll;
dfs1(0);
dfs2(n);
printf("%llu\n",ans);
return 0;
}
AGC 026 C - String Coloring的更多相关文章
- AtCoder Grand Contest #026 C - String Coloring
Time Limit: 3 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement You are given a st ...
- E2. String Coloring (hard version)(贪心)
E2. String Coloring (hard version) time limit per test 1 second memory limit per test 256 megabytes ...
- E1. String Coloring (easy version)(贪心)
E1. String Coloring (easy version) time limit per test 1 second memory limit per test 256 megabytes ...
- AGC 025 B - RGB Coloring
B - RGB Coloring Time limit : 2sec / Memory limit : 1024MB Score : 700 points Problem Statement Taka ...
- Codeforces Round #617 (Div. 3) String Coloring(E1.E2)
(easy version): 题目链接:http://codeforces.com/contest/1296/problem/E1 题目一句话就是说,两种颜色不同的字符可以相互换位, 问,对这字符串 ...
- Codeforces 1296E2. String Coloring (hard version)
这道题和HDU1257一模一样,一开始窝都用贪心直接解,没法理解为什么求一个最长下降序列,直到看了巨巨的题解,先给出一个定理,Dilworth's theorem,离散学不好,补题两行泪,该定理是说, ...
- Codeforces 1296E1 - String Coloring (easy version)
题目大意: 给定一段长度为n的字符串s 你需要给每个字符进行涂色,然后相邻的不同色的字符可以进行交换 需要保证涂色后能通过相邻交换把这个字符串按照字典序排序(a~z) 你只有两种颜色可以用来涂 问是否 ...
- AtCoder Grand Contest 026 D - Histogram Coloring
一列中有两个连续的元素,那么下一列只能选择选择正好相反的填色方案(因为连续的地方填色方案已经确定,其他地方也就确定了) 我们现将高度进行离散化到Has数组中,然后定义dp数组 dp[i][j] 表示前 ...
- AGC 26 D Histogram Coloring
题目 将柱子的高度离散化$\DeclareMathOperator{\dp}{dp}$ 设第 $i$ 根柱子实际高度是 $h_i$,离散化之后的高度是 $g_i$:第 $i$ 高的高度是 $H_i$, ...
随机推荐
- 20、redis和memcached比较?
1.Redis和Memcache都是将数据存放在内存中,都是内存数据库.不过memcache还可用于缓存其他东西,例如图片.视频等等: 2.Redis不仅仅支持简单的k/v类型的数据,同时还提供lis ...
- spring cloud config 详解
Spring Cloud 为开发人员提供了一系列的工具来快速构建分布式系统的通用模型 .例如:配置管理.服务发现.断路由.智能路由.微代理.控制总线.一次性Token.全局锁.决策竞选.分布式sess ...
- mybatis 显示 sql日志
#项目日志logging.level.com.zhang.com=debug #mybatis sql相关日志显示logging.level.org.mybatis.spring=DEBUGloggi ...
- typeof的用法
typeof可以返回变量的类型,返回值为字符串,其值有 "undefined" "boolean" "string" "numbe ...
- [hadoop][会装]hadoop ha模式安装
1.简介 2.X版本后namenode支持了HA特性,使得整个文件系统的可用性更加增强. 2.安装前提 zookeeper集群,zookeeper的安装参考[hadoop][会装]zookeeper安 ...
- Django REST Framework JWT提供的登录签发的视图
Django REST Framework JWT提供了一个视图.在我们登录的时候,会校验用户名.密码是否正确.如果信息无误,可以返回一个JWT token.就可以简单地实现了记录用户登录状态. 用法 ...
- 怎么制作CHM格式电子书
CHM格式的帮助文件相信大家都不陌生,CHM文件形式多样,使用方便,深受大家喜爱. 今天给大家介绍一种把文本文件转换为CHM格式电子书的方法. 前期准备过程 1 下载QuickCHM v2.6文件 去 ...
- Intersection of Two Linked Lists——经典问题
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- Two Sum ——经典的哈希表的题
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- python写的的简单的爬虫小程序
import re import urllib def getHtml(url): page=urllib.urlopen(url) html=page.read() return html def ...