sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛
Mountain Subsequences
题目描述
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.
输入
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.
输出
示例输入
4
abca
示例输出
4
提示
aba, aca, bca, abca
来源
#include <iostream>
#include <cstring>
#define maxn 100005
#define mod 2012
using namespace std;
char str[maxn];
int dp[],dl[maxn],dr[maxn],s[maxn];
int main()
{
int n;
while(cin>>n)
{
cin>>str;
for(int i=;i<n;i++)
s[i]=str[i]-'a';
memset(dp,,sizeof(dp));
memset(dl,,sizeof(dl));
memset(dr,,sizeof(dr));
for(int i=;i<n;i++)
{
for(int j=;j<s[i];j++)
dl[i]=(dl[i]+dp[j])%mod;//统计前i个满足小于(s[i])条件的个数
dp[s[i]]=(dp[s[i]]+dl[i]+)%mod;//加上当前满足条件的个数为下一个做准备
}
memset(dp,,sizeof(dp));
for(int i=n-;i>=;i--)
{
for(int j=;j<s[i];j++)
dr[i]=(dr[i]+dp[j])%mod;
dp[s[i]]=(dp[s[i]]+dr[i]+)%mod;
}
int ans=;
for(int i=;i<n;i++)
ans=(ans+dl[i]*dr[i])%mod;
cout<<ans<<endl;
}
return ;
}
sdut Mountain Subsequences 2013年山东省第四届ACM大学生程序设计竞赛的更多相关文章
- Alice and Bob(2013年山东省第四届ACM大学生程序设计竞赛)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very m ...
- 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server
点击打开链接 2226: Contest Print Server Time Limit: 1 Sec Memory Limit: 128 MB Submit: 53 Solved: 18 [Su ...
- 2013年山东省第四届ACM大学生程序设计竞赛J题:Contest Print Server
题目描述 In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code ...
- 2013年山东省第四届ACM大学生程序设计竞赛E题:Alice and Bob
题目描述 Alice and Bob like playing games very much.Today, they introduce a new game. There is a polynom ...
- 2013年山东省第四届ACM大学生程序设计竞赛 Alice and Bob
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 题目描述 Alice and Bob like playing games very ...
- 山东省第四届ACM大学生程序设计竞赛解题报告(部分)
2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...
- UPC 2224 / “浪潮杯”山东省第四届ACM大学生程序设计竞赛 1008 Boring Counting 主席树
Problem H:Boring Counting Time Limit : 6000/3000ms (Java/Other) Memory Limit : 65535/32768K (Java/ ...
- [2012山东省第三届ACM大学生程序设计竞赛]——n a^o7 !
n a^o7 ! 题目:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2413 Time Lim ...
- angry_birds_again_and_again(2014年山东省第五届ACM大学生程序设计竞赛A题)
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2877 题目描述 The problems ca ...
随机推荐
- PTCSolution 关注
2013.12.28更新: 经过几次整理和再次租赁下线,点击数明显增加,现在995下线点击数3413.再将2页半的点击数低的下线替换掉,AVG肯定超过4. 这么短的时间整理效果如此明显是我没有想到 ...
- VMware虚拟机怎么从U盘启动
VMware虚拟机怎么从U盘启动 发布时间:2016-01-12 18:50发布者:系统城-xtcjh浏览数:41951 VMware Workstation虚拟机可以安装各种操作系统,很多用户就想在 ...
- iOS:quartz2D绘图(处理图像,绘制图像并添加水印)
绘制图像既可以重写drawRect:方法并在该方法中绘制,也可以不用重写该方法,它有封装好的函数获取自己的图像绘制上下文,即UIGraphicsBeginImageContext(CGSize siz ...
- Java中文语言处理HanLP
官网:http://hanlp.linrunsoft.com/ 1.中文分词:http://hanlp.linrunsoft.com/doc/_build/html/segment.html 2.摘要 ...
- Neo4J简单了解
1.什么是Neo4j Neo4j是由java实现的开源NOSQL图数据库 数据库分为关系型和非关系型两种类型. 其中非关系型又分为Graph(图形),Document(文档),Cloumn Famil ...
- Python Pygal绘制世界人口地图
数据集可在 https://datahub.io/JohnSnowLabs/population-figures-by-country 下载 #coding=utf-8 import json fro ...
- Node.js mm131图片批量下载爬虫1.01 增加断点续传功能
这里的断点续传不是文件下载时的断点续传,而是指在爬行页面时有时会遇到各种网络中断而从中断前的页面及其数据继续爬行的过程,这个过程和断点续传原理上相似故以此命名.我的具体做法是:在下载出现故障或是图片已 ...
- 升级_开阔视野之Oracle图形化升级(dbca建库后升级)—10.2.0.1.0升为10.2.0.5.0
***********************************************声明*************************************************** ...
- 易语言调用csharp写的COM组件的程序在Win2008上奔溃的解决办法
易语言调用csharp写的COM组件,除了要注册csharp写的dll之外(由于是.net代码,需要用.net自带的注册工具RegAsm.exe注册,具体注册方法为: C:\WINDOWS\Micro ...
- Python Hashtable的理解
一个对象当其生命周期内的hash值不发生改变,而且可以跟其他对象进行比较时,这个对象就是Hashtable的.两者Hashtable的对象只有具有相同的hash值时才能判断为相同的对象. ...