codeforces 314E Sereja and Squares
discription
Sereja painted n points on the plane, point number i (1 ≤ i ≤ n) has coordinates (i, 0). Then Sereja marked each point with a small or large English letter. Sereja don't like letter "x", so he didn't use it to mark points. Sereja thinks that the points are marked beautifully if the following conditions holds:
- all points can be divided into pairs so that each point will belong to exactly one pair;
- in each pair the point with the lesser abscissa will be marked with a small English letter and the point with the larger abscissa will be marked with the same large English letter;
- if we built a square on each pair, the pair's points will be the square's opposite points and the segment between them will be the square's diagonal, then among the resulting squares there won't be any intersecting or touching ones.
Little Petya erased some small and all large letters marking the points. Now Sereja wonders how many ways are there to return the removed letters so that the points were marked beautifully.
Input
The first line contains integer n the number of points (1 ≤ n ≤ 105). The second line contains a sequence consisting of n small English letters and question marks — the sequence of letters, that mark points, in order of increasing x-coordinate of points. Question marks denote the points without letters (Petya erased them). It is guaranteed that the input string doesn't contain letter "x".
Output
In a single line print the answer to the problem modulo 4294967296. If there is no way to return the removed letters, print number 0.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
Example
4
a???
50
4
abc?
0
6
abc???
1 转移贼好想,然而什么在codeforces上 N^2过 10^5都是骗人的mmp
各种常数优化之后还是活生生被卡成儿子hhhh先这样吧假装我A了的样子hhh
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
#define maxn 100005
#define ll unsigned int
using namespace std;
ll dp[maxn],pre,ppre;
int n;
char s[maxn];
bool is[maxn];
int main(){
scanf("%d",&n);
scanf("%s",s+); if(s[n]!='?'){
puts("");
return ;
} for(int i=;i<=n;i++) is[i]=!(s[i]=='?'); dp[]=;
for(int i=,k;i<=n;i++){
for(k=;i+k<=n&&is[i+k];k++);
k--;
if(k>=){
for(int j=i+k;j>k;j--) dp[j]=dp[j-k-];
for(int j=k;j>=;j--) dp[j]=;
} i+=k+,pre=;
for(int j=;j<=i;j++){
ppre=dp[j];
dp[j]=pre+dp[j+];
pre=ppre*;
}
} cout<<dp[]<<endl;
return ;
}
codeforces 314E Sereja and Squares的更多相关文章
- Codeforces.314E.Sereja and Squares(DP)
题目链接 http://www.cnblogs.com/TheRoadToTheGold/p/8443668.html \(Description\) 给你一个擦去了部分左括号和全部右括号的括号序列, ...
- codeforces 425D Sereja and Squares n个点构成多少个正方形
输入n个点,问可以构成多少个正方形.n,xi,yi<=100,000. 刚看题的时候感觉好像以前见过╮(╯▽╰)╭最近越来越觉得以前见过的题偶尔就出现类似的,可是以前不努力啊,没做出来的没认真研 ...
- CF 314 E. Sereja and Squares
E. Sereja and Squares http://codeforces.com/contest/314/problem/E 题意: 给你一个擦去了部分左括号和全部右括号的括号序列,括号有25种 ...
- Codeforces 314 E. Sereja and Squares
http://codeforces.com/contest/314/problem/E 题意: 原本有一个合法的括号序列 擦去了所有的右括号和部分左括号 问有多少种填括号的方式使他仍然是合法的括号序列 ...
- Codeforces Round #243 (Div. 1)——Sereja and Squares
题目链接 题意: 给n个点,求能组成的正方形的个数. 四边均平行与坐标轴 大神的分析: 经典题 我们考虑每一种x坐标,显然仅仅有<= sqrt{N}个x坐标出现了> sqrt{N}次,我们 ...
- Codeforces 599D Spongebob and Squares(数学)
D. Spongebob and Squares Spongebob is already tired trying to reason his weird actions and calculati ...
- Codeforces 425A Sereja and Swaps(暴力枚举)
题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...
- codeforces 425C Sereja and Two Sequences(DP)
题意读了好久才读懂....不知道怎么翻译好~~请自便~~~ http://codeforces.com/problemset/problem/425/C 看懂之后纠结好久...不会做...仍然是看题解 ...
- codeforces B. Sereja and Stairs 解题报告
题目链接:http://codeforces.com/problemset/problem/381/B 题目意思:给定一个m个数的序列,需要从中组合出符合楼梯定义 a1 < a2 < .. ...
随机推荐
- ViBe(Visual Background extractor)背景建模或前景检测
ViBe算法:ViBe - a powerful technique for background detection and subtraction in video sequences 算法官网: ...
- WCF分布式开发步步为赢(13):WCF服务离线操作与消息队列MSMQ
之前曾经写过一个关于MSMQ消息队列的文章:WCF分布式开发必备知识(1):MSMQ消息队列 ,当时的目的也是用它来作为学习WCF 消息队列MSMQ编程的基础文章.在那篇文章里,我们详细介绍了MSMQ ...
- xmlns:sys="clr-namespace:System;assembly=mscorlib" NOTE: System;与assembly中间不能有空格
xmlns:sys="clr-namespace:System;assembly=mscorlib" NOTE: System;与assembly中间不能有空格 否则报错, Er ...
- 粉刷匠(bzoj 1296)
Description windy有 N 条木板需要被粉刷. 每条木板被分为 M 个格子. 每个格子要被刷成红色或蓝色. windy每次粉刷,只能选择一条木板上一段连续的格子,然后涂上一种颜色. 每个 ...
- [转]使用 LDAP 组或角色限制访问,包含部分单点登录SSO说明
参考:http://www-01.ibm.com/support/knowledgecenter/api/content/SSEP7J_10.2.2/com.ibm.swg.ba.cognos.crn ...
- python3 多态,绑定方法与非绑定方法
多态:同一种事物的不同形态(一个抽象类有多个子类,因而多态的概念依赖于继承) 1. 序列类型有多种形态:字符串,列表,元组. 2. 动物有多种形态:人,狗,猪 多态性:多态性是指具有不同功能的函数可以 ...
- dd命令测试硬盘I/O速度
[root@bogon ~]# dd if=/dev/zero of=/home/tom.a.txt bs=200MB count=1记录了1+0 的读入记录了1+0 的写出200000000字节(2 ...
- HDU1045(二分图经典建模)
Fire Net Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- Kuangbin 带你飞专题十一 网络流题解 及模版 及上下界网络流等问题
首先是几份模版 最大流:虽然EK很慢但是优势就是短.求最小割的时候可以根据增广时的a数组来判断哪些边是割边.然而SAP的最大流版我只会套版,并不知道该如何找到这个割边.在尝试的时候发现了一些问题.所以 ...
- js数组高效去重
http://blog.csdn.net/chengxuyuan20100425/article/details/8497277 这个方法的思路是先把数组排序,然后比较相邻的两个值. 排序的时候用的J ...
先这样吧假装我A了的样子hhh