考虑DP。

如果把转移看出当前位填什么数的话,这样是有后效性的。

如果考虑当前的序列是将1至n依次插入序列中的话。

考虑将i插入1到i-1的序列中,如果插入到<号中或者首部,那么最后就会多出一个大于号。

如果插入到>号中或者尾部,那么最后就会多出一个小于号。

所以定义状态dp[i][j]表示1到i组成的序列中,小于号的数目为j的方法数。转移方程即为所求。

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi 3.1415926535
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int res=, flag=;
char ch;
if((ch=getchar())=='-') flag=;
else if(ch>=''&&ch<='') res=ch-'';
while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
return flag?-res:res;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... int dp[N][N]; int dfs(int x, int y){
if (~dp[x][y]) return dp[x][y];
if (y==||y==x-) return dp[x][y]=;
if (y>=x) return ;
int ans=(dfs(x-,y)*(y+)%+dfs(x-,y-)*(x-y)%)%;
return dp[x][y]=ans;
}
int main ()
{
int n, k;
mem(dp,-);
scanf("%d%d",&n,&k);
printf("%d\n",dfs(n,k));
return ;
}

最新文章

  1. java中的等于
  2. C++ 函数形参发生动态绑定时指针增长步长与静态类型一致
  3. 烂泥:php5.6源码安装与apache集成
  4. Knockout.Js案例一Introduction
  5. Android -- 闹钟服务的使用(启动与停止)
  6. VM安装mac及dmg文件转换iso
  7. Android总结篇系列:Android 权限
  8. DCMTK3.6.0(MD支持库)安装说明
  9. stm32学习笔记----双串口同时打开时的printf()问题
  10. 初识API函数
  11. iOS学习之基本概念
  12. Codeforces Round #190 (Div. 2) 水果俩水题
  13. js实现placeholder效果
  14. 关于css的默认宽度
  15. 解决错误 fatal error C1010: unexpected end of file while looking for precompiled head
  16. 我的MYSQL学习心得(四)
  17. js实现图片旋转、模板文件查看图片大图之记录篇[二]
  18. error: can&#39;t copy &#39;docx\templates\default-docx-template&#39;: doesn&#39;t exist or not a regular file --------------- Failed building wheel for python-docx; python-docx的安装使用;python操作word
  19. IdentityServer(14)- 通过EntityFramework Core持久化配置和操作数据
  20. define和typedef的区别

热门文章

  1. 【blockly教程】第六章 Blockly的进阶
  2. 长沙优步Uber奖励政策(7.27~8.2)
  3. 【NIS】深入了解NIS
  4. 利尔达NB-IOT模块烧写固件的步骤
  5. 「专题训练」Hard problem(Codeforces Round #367 Div. 2 C)
  6. docker官网安装
  7. 跟浩哥学自动化测试Selenium -- 我的第一个Demo (2)
  8. .NET邮件发送详情
  9. Unity编辑器 - 资源修改立即写入磁盘AssetDataBase.SaveAssets()
  10. C 数数位 while循环