题面在这里!

比较简单的折半搜索,推一下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的更多相关文章

  1. 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 ...

  2. E2. String Coloring (hard version)(贪心)

    E2. String Coloring (hard version) time limit per test 1 second memory limit per test 256 megabytes ...

  3. E1. String Coloring (easy version)(贪心)

    E1. String Coloring (easy version) time limit per test 1 second memory limit per test 256 megabytes ...

  4. AGC 025 B - RGB Coloring

    B - RGB Coloring Time limit : 2sec / Memory limit : 1024MB Score : 700 points Problem Statement Taka ...

  5. Codeforces Round #617 (Div. 3) String Coloring(E1.E2)

    (easy version): 题目链接:http://codeforces.com/contest/1296/problem/E1 题目一句话就是说,两种颜色不同的字符可以相互换位, 问,对这字符串 ...

  6. Codeforces 1296E2. String Coloring (hard version)

    这道题和HDU1257一模一样,一开始窝都用贪心直接解,没法理解为什么求一个最长下降序列,直到看了巨巨的题解,先给出一个定理,Dilworth's theorem,离散学不好,补题两行泪,该定理是说, ...

  7. Codeforces 1296E1 - String Coloring (easy version)

    题目大意: 给定一段长度为n的字符串s 你需要给每个字符进行涂色,然后相邻的不同色的字符可以进行交换 需要保证涂色后能通过相邻交换把这个字符串按照字典序排序(a~z) 你只有两种颜色可以用来涂 问是否 ...

  8. AtCoder Grand Contest 026 D - Histogram Coloring

    一列中有两个连续的元素,那么下一列只能选择选择正好相反的填色方案(因为连续的地方填色方案已经确定,其他地方也就确定了) 我们现将高度进行离散化到Has数组中,然后定义dp数组 dp[i][j] 表示前 ...

  9. AGC 26 D Histogram Coloring

    题目 将柱子的高度离散化$\DeclareMathOperator{\dp}{dp}$ 设第 $i$ 根柱子实际高度是 $h_i$,离散化之后的高度是 $g_i$:第 $i$ 高的高度是 $H_i$, ...

随机推荐

  1. bootstrap框架的搭建

    bootstrap框架 Bootstrap,来自 Twitter,是目前最受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快 ...

  2. Codeforces Round #494 (Div. 3)

    刚好在考完当天有一场div3,就开了个小号打了,打的途中被辅导员喊去帮忙,搞了二十分钟-_-||,最后就出了四题,题解如下:题目链接:http://codeforces.com/contest/100 ...

  3. Chrome 浏览器 autocomplete off无效

    在表单填写时突然发现autocomplete 失效了 网上搜索后得出大概意思是在某些情况下确实无效[捂脸] 解决方案 大致原因是浏览器默认为type为password的input标签自动填充密码 这样 ...

  4. vs调试 配置IISExpress允许局域网内部访问

    内网可访问后,本机不能使用localhost   1.找到IISExpress的配置文件,位于 <文档>/IISExpress/config文件夹下,打开applicationhost.c ...

  5. 更改控件中DrawableLeft图片的大小,图片与文字的距离

    Drawable drawable=getResources().getDrawable(R.drawable.xx); //获取图片 drawable.setBounds(left, top, ri ...

  6. Spring注解@Resource和@Autowired区别对比、spring扫描的默认bean的Id、程序获取spring容器对象

    -------------------------注解扫面的bean的ID问题-------------------------- 0.前提需要明白注解扫描出来的bean的id默认是类名首字母小写,当 ...

  7. HTTP和HTTPS详解。

    一,HTTP和HTTPS基本概念 深入学习某个东西时,我们先来从维基百科上看看它俩的概念. HTTP:超文本传输协议(英文:HyperText Transfer Protocol,缩写:HTTP)是一 ...

  8. SUSE 11.3 linux ISO下载地址

    http://linux.iingen.unam.mx/pub/Linux/Suse/isos/SLES11/ SLE-11-SP3-SDK-DVD-i586-GM-DVD1.iso 6deaa960 ...

  9. 基于 Arduino 开发板,这款插座是可编程且开源的

    基于 Arduino 开发板,这款插座是可编程且开源的 https://www.oschina.net/news/74861/open-source-socket https://github.com ...

  10. MySQL多线程复制故障(slave_pending_jobs_size_max)

    MySQL多线程复制故障(slave_pending_jobs_size_max) http://www.xuchanggang.cn/archives/1079.html