B - Byteland Trip

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

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

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

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

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

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define fi first
  4. #define se second
  5. #define mk make_pair
  6. #define PII pair<int, int>
  7. #define PLI pair<LL, int>
  8. #define ull unsigned long long
  9. using namespace std;
  10.  
  11. const int N = ;
  12. const int inf = 0x3f3f3f3f;
  13. const LL INF = 0x3f3f3f3f3f3f3f3f;
  14. const int mod = 1e9 + ;
  15. const double eps = 1e-;
  16.  
  17. int n, m;
  18. LL dp1[N][N], dp2[N][N], f[N], ans[N];
  19. char s[N];
  20.  
  21. void add(LL &a, LL b) {
  22. a += b; if(a >= mod) a -= mod;
  23. }
  24.  
  25. int main() {
  26. for(int i=f[]=; i < N; i++) f[i] = f[i-]*i%mod;
  27. scanf("%s", s + );
  28. m = strlen(s + );
  29. for(int i = ; i <= m; i++)
  30. if(s[i] == '<' || s[i] == '>') s[++n] = s[i];
  31. if(n == ) {
  32. puts("");
  33. return ;
  34. }
  35. dp1[][] = ;
  36. for(int i = ; i <= n; i++) {
  37. for(int j = ; j <= i; j++) {
  38. if(s[i] == '<') {
  39. add(dp1[i][j], dp1[i-][j]*j%mod);
  40. add(dp1[i][j], dp1[i-][j+]*(j+)%mod*j%mod);
  41. } else {
  42. if(j) add(dp1[i][j], dp1[i-][j-]);
  43. add(dp1[i][j], dp1[i-][j]*j%mod);
  44. }
  45. }
  46. }
  47. dp2[n+][] = ;
  48. for(int i = n; i >= ; i--) {
  49. for(int j = ; j <= n-i+; j++) {
  50. if(s[i] == '<') {
  51. if(j) add(dp2[i][j], dp2[i+][j-]);
  52. add(dp2[i][j], dp2[i+][j]*j%mod);
  53. } else {
  54. add(dp2[i][j], dp2[i+][j]*j%mod);
  55. add(dp2[i][j], dp2[i+][j+]*(j+)%mod*j%mod);
  56. }
  57. }
  58. }
  59. ans[] = dp2[][];
  60. ans[n] = dp1[n-][];
  61. for(int i = ; i < n; i++) {
  62. for(int j = ; j < i; j++) {
  63. add(ans[i], dp1[i-][j]*dp2[i+][j]%mod*f[j]%mod*f[j]%mod*%mod);
  64. add(ans[i], dp1[i-][j]*dp2[i+][j+]%mod*f[j]%mod*f[j+]%mod);
  65. if(j > ) add(ans[i], dp1[i-][j]*dp2[i+][j-]%mod*f[j]%mod*f[j-]%mod);
  66. }
  67. }
  68. for(int i = ; i <= n; i++) printf("%lld ", ans[i]);
  69. return ;
  70. }
  71.  
  72. /*
  73. */

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. weUI框架在github下载地址

    1.公众号样式UI库的下载地址: https://github.com/Tencent/weui 2.微信小程序UI库的下载地址:https://github.com/Tencent/weui-wxs ...

  2. bzoj千题计划115:bzoj1024: [SCOI2009]生日快乐

    http://www.lydsy.com/JudgeOnline/problem.php?id=1024 枚举横着切还是竖着切,一边儿分多少块 #include<cstdio> #incl ...

  3. 关于File 文件操作

    1.通过Context.getExternalFilesDir()方法可以获取到 SDCard/Android/data/你的应用的包名/files/ 目录,一般放一些长时间保存的数据2.通过Cont ...

  4. 半小时让你成为EXCEL高手

  5. bzoj 5055: 膜法师——树状数组

    Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然,他能为长者所续的时间,为这三个维度上能量的乘 ...

  6. c++刷题(27/100)反转单项链表,链表的倒数第k个

    题目1:调整数组顺序使奇数位于偶数前面 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位 ...

  7. Codeforces Round #540 (Div. 3)题解

    题目链接: https://codeforces.com/contest/1118 A题: 题意: q次查询,给你一个n,要你用1和2来凑出n,1的花费为a,2的花费为b,求花费的最小值. 思路: 我 ...

  8. 【译】第十篇 SQL Server代理使用代理帐户

    本篇文章是SQL Server代理系列的第十篇,详细内容请参考原文 在这一系列的上一篇,你查看了msdb库下用于授权访问SQL Server代理的安全角色.这些角色包括SQLAgentUserRole ...

  9. 【方法】纯jQuery实现星巴克官网导航栏效果

    前言 大冬天的没得玩,只能和代码玩. 所以就无聊研究了一下星巴克官网,在我看来应该是基本还原吧~ 请各位大神指教! 官网效果图 要写的就是最上方的会闪现的白色条条 效果分析 1.在滚动条往下拉到一定距 ...

  10. [转]QList内存释放

    QList<T> 的释放分两种情况: 1.T的类型为非指针,这时候直接调用clear()方法就可以释放了,看如下测试代码 #include <QtCore/QCoreApplicat ...