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. Codeforces Round #477 (rated, Div. 2, based on VK Cup 2018 Round 3) D 贪心

    http://codeforces.com/contest/967/problem/D 题目大意: 有n个服务器,标号为1~n,每个服务器有C[i]个资源.现在,有两个任务需要同时进行,令他为x1,x ...

  2. windows设置代理.bat 脚本

    按照下列脚本复制到记事本中,保存,重命名后缀为.bat,使用时双击即可. 设置代理.bat,修改下列脚本中的代理地址和端口号 @echo off echo 开始设置IE代理上网 reg add &qu ...

  3. AspNetPager控件的最基本用法

    AspNetPager控件是一个基于.net的第三方免费开源控件,具有开发高效.使用方便.功能完整等优点.它弥补了GridView内置分页以及PageDatasource类辅助分页的不足,将分页数据逻 ...

  4. mysql 距离函数

    要有超级权限 SET GLOBAL log_bin_trust_function_creators = 1;DELIMITER $$CREATE DEFINER=`root`@`localhost` ...

  5. 不忘初心,方得始终——NOIP2016前的感悟

    不忘初心,方得始终 袛园精舍钟声响,奏诸世事本无常.沙罗双树失花色,盛者转衰如沧桑.骄者难久,恰如春宵一梦.猛者遂灭,好似风前之尘.    ——题记   人生中最令人恐惧的恐怕就是选择了,现在的你拥有 ...

  6. springboot+mybatis使用PageHelper分页

    项目结构和spring搭建mybatis请参考springboot整合mybatis.在这个基础上配置分页. 一:导入PageHelper依赖 <dependency> <group ...

  7. linux nginx服务 反向代理 负载均衡 nfs服务

    一.nginx服务 1.首先软件停用firewall #systemctl stop firewalld stop:本次停用 disable:开机停用 enable:开机启用 #ps aux | gr ...

  8. mysql定时删除数据

    删除三天前的数据的sql DELETE FROM table WHERE created_on < DATE_SUB(CURDATE(),INTERVAL 3 DAY); CURDATE() 返 ...

  9. Android手动回收bitmap,引发Canvas: trying to use a recycled bitmap处理

    在做Android的开发的时候,在ListView 或是 GridView中需要加载大量的图片,为了避免加载过多的图片引起OutOfMemory错误,设置了一个图片缓存列表 Map<String ...

  10. perl6 HTTP::UserAgent发送post

    use HTTP::UserAgent; my $ua = HTTP::UserAgent.new; say 'All method:'; say $ua.^methods; my %data = : ...