13年山东省赛 Mountain Subsequences(dp)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
Mountain Subsequences
Time Limit: 1 Sec Memory Limit: 128 MB
Description
Coco is a beautiful ACMer girl living in a very beautiful mountain. There are many trees and flowers on the mountain, and there are many animals and birds also. Coco like the mountain so much that she now name some letter sequences as Mountain Subsequences.
A Mountain Subsequence is defined as following:
1. If the length of the subsequence is n, there should be a max value letter, and the subsequence should like this, a1 < ...< ai < ai+1 < Amax > aj > aj+1 > ... > an
2. It should have at least 3 elements, and in the left of the max value letter there should have at least one element, the same as in the right.
3. The value of the letter is the ASCII value.
Given a letter sequence, Coco wants to know how many Mountain Subsequences exist.
Input
Input contains multiple test cases.
For each case there is a number n (1<= n <= 100000) which means the length of the letter sequence in the first line, and the next line contains the letter sequence.
Please note that the letter sequence only contain lowercase letters.
Output
For each case please output the number of the mountain subsequences module 2012.
Sample Input
4
abca
Sample Output
4
HINT
The 4 mountain subsequences are:
aba, aca, bca, abca
题意:满足a[i]<a[i+1]<......<a[j]>a[j+1]>......a[k]的子序列有多少个(左边和右边的长度都至少为1)
分析:算出从左向右以当前字母结尾的上升子序列的个数和从右向左的。。。
然后再把左边和右边的乘一下就行
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
#define MAXN 100010
int dp[];
int a[MAXN];
int dp1[MAXN],dp2[MAXN];
int main()
{
ios::sync_with_stdio(false);
int n;
char s;
while(cin>>n){
for(int i=;i<n;i++){
cin>>s;
a[i]=s-'a';
}
CLR(dp,);
CLR(dp1,);
for(int i=;i<n;i++){
for(int j=;j<a[i];j++) dp1[i]+=dp[j];
while(dp1[i]>=)dp1[i]-=;
dp[a[i]]+=dp1[i]+;
while(dp[a[i]]>=)dp[a[i]]-=;
}
CLR(dp,);
CLR(dp2,);
for(int i=n-;i>=;i--){
for(int j=;j<a[i];j++) dp2[i]+=dp[j];
while(dp2[i]>=)dp2[i]-=;
dp[a[i]]+=dp2[i]+;
while(dp[a[i]]>=)dp[a[i]]-=;
}
int ans=;
for(int i=;i<n;i++){
ans=(ans+dp1[i]*dp2[i])%;
}
cout<<ans<<endl;
}
return ;
}
13年山东省赛 Mountain Subsequences(dp)的更多相关文章
- 13年山东省赛 The number of steps(概率dp水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud The number of steps Time Limit: 1 Sec Me ...
- 13年山东省赛 Boring Counting(离线树状数组or主席树+二分or划分树+二分)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud 2224: Boring Counting Time Limit: 3 Sec ...
- 2018ACM山东省赛 Games(dp取数)
Games Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Problem Description Alice and Bob ...
- 2013年山东省赛F题 Mountain Subsequences
2013年山东省赛F题 Mountain Subsequences先说n^2做法,从第1个,(假设当前是第i个)到第i-1个位置上哪些比第i位的小,那也就意味着a[i]可以接在它后面,f1[i]表示从 ...
- sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛
Mountain Subsequences 题目描述 Coco is a beautiful ACMer girl living in a very beautiful mountain. There ...
- 山东省第四届省赛 E-Mountain Subsequences
Description Coco is a beautiful ACMer girl living in a very beautiful mountain. There are many trees ...
- sdutoj 2607 Mountain Subsequences
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2607 Mountain Subsequence ...
- Triangle (第8届山东省赛的某题)
triangle(第8届山东省赛的某题) 传送门 题意:喵了个呜,这题意真是峰回路转啊.懒死了,不想描述. 做法:我们拿set或线段树维护exp的最小值,每次取出exp值最小的边,删除之.并更新这条边 ...
- HEX SDUT 3896 17年山东省赛D题
HEX SDUT 3896 17年山东省赛D题这个题是从矩形的左下角走到右上角的方案数的变形题,看来我对以前做过的题理解还不是太深,或者是忘了.对于这种题目,直接分析它的性质就完事了.从(1,1)走到 ...
随机推荐
- 关于Ajax的技术组成与核心原理
1.Ajax 特点: 局部刷新.提高用户的体验度,数据从服务器商加载 2.AJax的技术组成 不是新技术,而是之前技术的整合 Ajax: Asynchronous Javascript And Xml ...
- linux查看磁盘空间
首先如果需要查看整个磁盘还剩多少空间,可以使用命令: df -h 如果你并不关心磁盘还剩余多少空间,只是需要知道当前的文件夹下的磁盘使用情况,可以使用如下命令: -h 上面使用du --max-dep ...
- Android开源框架之SwipeListView导入及模拟QQ侧滑
SwipeListView是Github上的一个开源框架,地址:https://github.com/47deg/android-swipelistview SwipeListView was bor ...
- Android开发之打开闪光灯录制视频
Android的SDK在线API上对录制视频的方法.步骤都写得非常清楚,但是如果没有一点思路,写起来也比较式费事.录制视频的全过程要打开闪光灯(可能是因为项目需要,或者特殊原因),则必须按照一定的顺序 ...
- SEO的URL如何优化才是最佳
原文地址:http://www.chinaz.com/web/2007/0413/6841.shtml 很多人都知道URL对SEO的重要之处,但是很多站点却忽略了站点的路径优化.今天本人在这里写几点关 ...
- C5-信号量与PV操作(iOS篇-细说信号量)
一.概述 信号量这种同步机制的概念. P, V操作(Dijkstra提出)的定义 github地址(iOS中的信号量是以1开始定义): https://github.com/sixleaves/sem ...
- DBA 经典面试题(4)
1.如果信息采集管理系统(ICM)崩溃了怎么办? 答案:所有其他的管理器都会继续工作.ICM只会处理队列控制请求,意思是开启和关闭其他并发的管理器. 2.你如何加速打补丁的过程? 答案: ...
- PHP文件目录copy
/**(2) PHP文件目录copy @param string $dirsrc 原目录名称字符串 @param string $dirto 目标目录名称字符串 */ function copyDir ...
- Eclipse代理设置
这段时间公司实行代理上网,不仅通过浏览器上网须要不停的输入username和password,在本地调试程序时候Eclipse居然也弹出框让输入username和password. 如图: 解决的方法 ...
- 使用ant自动编译、打包生成apk文件
上次使用命令行生成apk文件<Android 命令行编译.打包生成apk文件>,学习命令行生成的目的是为了编写ant打下基础. 一. ant环境 下载ant包,配置环境变量 二.ant编译 ...