B - Byteland Trip

题目大意:给你一个由'<' 和 '>'组成的串, 如果在'<' 只能前往编号比它小的任意点, 反之只能前往比它大的任意点,问你能遍历所有点

并且每个点只走一次终点在各个位置的方案数。

思路:感觉这种右能从左边跑到右边又跑回来的dp很难搞,如果我们确定一个终点, 如果知道它左边点一共出来几次,右边的点一共出来几次

那么方案数就很好求了, 所以我们定义dp1[ i ][ j ] 表示前 i 个点,遍历所有点并且向右出去 j 次的的方案数, dp2[ i ][ j ]就是反过来的。

对于每个点,我们枚举左边出来几次就好啦。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define PLI pair<LL, int>
#define ull unsigned long long
using namespace std; const int N = ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int n, m;
LL dp1[N][N], dp2[N][N], f[N], ans[N];
char s[N]; void add(LL &a, LL b) {
a += b; if(a >= mod) a -= mod;
} int main() {
for(int i=f[]=; i < N; i++) f[i] = f[i-]*i%mod;
scanf("%s", s + );
m = strlen(s + );
for(int i = ; i <= m; i++)
if(s[i] == '<' || s[i] == '>') s[++n] = s[i];
if(n == ) {
puts("");
return ;
}
dp1[][] = ;
for(int i = ; i <= n; i++) {
for(int j = ; j <= i; j++) {
if(s[i] == '<') {
add(dp1[i][j], dp1[i-][j]*j%mod);
add(dp1[i][j], dp1[i-][j+]*(j+)%mod*j%mod);
} else {
if(j) add(dp1[i][j], dp1[i-][j-]);
add(dp1[i][j], dp1[i-][j]*j%mod);
}
}
}
dp2[n+][] = ;
for(int i = n; i >= ; i--) {
for(int j = ; j <= n-i+; j++) {
if(s[i] == '<') {
if(j) add(dp2[i][j], dp2[i+][j-]);
add(dp2[i][j], dp2[i+][j]*j%mod);
} else {
add(dp2[i][j], dp2[i+][j]*j%mod);
add(dp2[i][j], dp2[i+][j+]*(j+)%mod*j%mod);
}
}
}
ans[] = dp2[][];
ans[n] = dp1[n-][];
for(int i = ; i < n; i++) {
for(int j = ; j < i; j++) {
add(ans[i], dp1[i-][j]*dp2[i+][j]%mod*f[j]%mod*f[j]%mod*%mod);
add(ans[i], dp1[i-][j]*dp2[i+][j+]%mod*f[j]%mod*f[j+]%mod);
if(j > ) add(ans[i], dp1[i-][j]*dp2[i+][j-]%mod*f[j]%mod*f[j-]%mod);
}
}
for(int i = ; i <= n; i++) printf("%lld ", ans[i]);
return ;
} /*
*/

2017-2018 ACM-ICPC, NEERC, Moscow Subregional Contest B - Byteland Trip dp的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering

    Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...

  4. ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time

    Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...

  5. 2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic(Kruskal思想)

    2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic 题意:有一张图,第i个点被占领需要ai个兵,而每个兵传送至该 ...

  6. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  7. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  8. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem D. Distance 迪杰斯特拉

    Problem D. Distance 题目连接: http://codeforces.com/gym/100714 Description In a large city a cellular ne ...

  9. 2010-2011 ACM-ICPC, NEERC, Moscow Subregional Contest Problem C. Contest 水题

    Problem C. Contest 题目连接: http://codeforces.com/gym/100714 Description The second round of the annual ...

随机推荐

  1. day1 java基础语法

    一.关键字:java关键字有:abstract boolean break byte case catch char class const continue default do double el ...

  2. select()函数

    select(),确定一个或多个套接口的状态,本函数用于确定一个或多个套接口的状态,对每一个套接口,调用者可查询它的可读性.可写性及错误状态信息,用fd_set结构来表示一组等待检查的套接口,在调用返 ...

  3. 四、Kafka 核心源码剖析

    一.Kafka消费者源码介绍 1.分区消费模式源码介绍 分区消费模式直接由客户端(任何高级语言编写)使用Kafka提供的协议向服务器发送RPC请求获取数据,服务器接受到客户端的RPC请求后,将数据构造 ...

  4. 谈谈Flash图表中数据的采集

    一般来说flash中的数据是不能被现有技术很容易采集到的,但是也不能谈flash色变,要具体问题具体分析,有些flash是可以通过一些分析发现背后的数据.然后采集就变得很容易了. 具体案例:搜房房价走 ...

  5. SpringBoot与异步任务、定时任务、邮件任务

    异步任务 在需要开启异步的服务加上注解:@Async @Service public class AsyncService { //告诉SpringBoot这是一个异步任务,SpringBoot会自动 ...

  6. POJ 2449 Remmarguts' Date (K短路 A*算法)

    题目链接 Description "Good man never makes girls wait or breaks an appointment!" said the mand ...

  7. sql server 查询本年的每个月的数据

    一.以一行数据的形式,显示本年的12月的数据,本示例以2017年为例,根据CreateDate字段判断,计算总和,查询语句如下: end) as '1月', end) as '2月', end) as ...

  8. 【译】第八篇 SQL Server代理使用外部程序

    本篇文章是SQL Server代理系列的第八篇,详细内容请参考原文 在这一系列的上一篇,学习了如何用SQL Server代理作业活动监视器监控作业活动和查看作业历史记录.在实时监控和管理SQL Ser ...

  9. jquery ajax complete 方法

    jquery ajax var ajaxTimeoutTest = $.ajax({ url:'',  //请求的URL timeout : 1000, //超时时间设置,单位毫秒 type : 'g ...

  10. 某大型网络社区传播性XSS分析

    某大型网络社区传播性XSS分析 这个XSS存在于天涯某个不起眼的子论坛,通过发布新帖子可以触发.         漏洞分析    论坛针对XSS有一定过滤措施,例如转义单双引号,过滤左右尖括号等等.所 ...