http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1968

题意:
对于任一种N的排列A,定义它的E值为序列中满足A[i]>A[i+1]的数的个数。给定N和K(K<=N<=1000),问N的排列中E值为K的个数。

思路:

这道题目和杭电的3664非常像。

d【i】【j】表示分析到i这个数时的E值为j的个数。

那么如何计算出d【i】【j】呢?得根据d【i-1】【j】和d【i-1】【j-1】递推出来。

①首先考虑d【i-1】【j】(此时不改变E值):

1)、因为此时i是最大的,所以插在最后不改变E值,方法数为1

2)、插入到每对逆序数中间,这样逆序数数量不会改变,方法数为j(因为一共有j对逆序对)

②然后是d【i-1】【j】(此时要让E值+1)

1)、插入到最前面,E值+1,方法数为1

2)、插入到不是逆序对中去,构成逆序对,E值+1,(i-1的数中一共有i-2对数,现在存在j-1对逆序对,那么i-2-j+1对数不是逆序对,可以插入到这几对数当中去),方法数为i-j+1

所以,最后的递推式就是

dp[i][j] = dp[i-][j-]*(i-j) + dp[i-][j]*(j+);
 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = + ; const int mod=; int dp[][]; void init()
{
for(int i=;i<=;i++) dp[i][]=;
for(int i=;i<=;i++)
{
for(int j=;j<i;j++){
dp[i][j]=(dp[i-][j-]*(i-j)+dp[i-][j]*(j+))%mod;
}
}
} int main()
{
int T;
int t,n,k;
init();
//freopen("in.txt","r",stdin);
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&t,&n,&k);
printf("%d %d\n",t,dp[n][k]); }
return ;
}

CSU 1968 Permutation Descent Counts的更多相关文章

  1. Permutation Descent Counts(递推)

    1968: Permutation Descent Counts Submit Page   Summary   Time Limit: 1 Sec     Memory Limit: 128 Mb  ...

  2. Codeforces 818B Permutation Game

    首先看一下题目 B. Permutation Game time limit per test 1 second memory limit per test 256 megabytes input s ...

  3. [Swift]LeetCode567. 字符串的排列 | Permutation in String

    Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. I ...

  4. 567. Permutation in String判断某字符串中是否存在另一个字符串的Permutation

    [抄题]: Given two strings s1 and s2, write a function to return true if s2 contains the permutation of ...

  5. 几种梯度下降方法对比(Batch gradient descent、Mini-batch gradient descent 和 stochastic gradient descent)

    https://blog.csdn.net/u012328159/article/details/80252012 我们在训练神经网络模型时,最常用的就是梯度下降,这篇博客主要介绍下几种梯度下降的变种 ...

  6. SPOJ - PERMJUMP Permutation Jumping

    Discription John likes playing the game Permutation Jumping. First he writes down a permutation A of ...

  7. [LeetCode] 567. Permutation in String 字符串中的全排列

    Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. I ...

  8. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  9. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

随机推荐

  1. JSTL的一些使用规范,坑

    三目表达式要加空格不然有些服务器解析不了 var maxBanners = ${maxBanners==null ? 3 : maxBanners}; forEach循环的长度正确使用方式 <c ...

  2. Ant教程

    安装ant,去http://ant.apache.org下载 配置环境变量(前提是配置了java环境变量) ANT_HOME G:\Software\ant1.9.7 //ant根目录 在PATH后添 ...

  3. svn-maven-tomcat自动发布脚本

    #!/bin/sh #svn-maven-tomcat自动发布脚本 #变量设置 svnpath=svn://10.60.10.120/研发部/xx-maven svnusername=xxx svnp ...

  4. csrf_token之全局认证与局部认证

    1.settings.py没有注释到csrf.当post请求的方式会报错. 接下来就解决问题! 1. django中间件 最多5个 - process_request 请求 - process_vie ...

  5. 170706、springboot编程之文件上传

    使用thymleaf模板,自行导入依赖! 一.单文件上传 1.编写单文件上传页面singleFile.html <!DOCTYPE html> <html xmlns="h ...

  6. docker基本操作命令

    1. 构建镜像 docker build -t centos/tomcat:7.0 2. 创建一个容器 docker run --name test-tomcat centos/tomcat:7.0 ...

  7. HI3518E用J-link烧写裸板fastboot u-boot流程

    Hi3518E的裸板烧写fastboot是不能像HI3531那样,可以通过FB直接烧写.遵循ARM9的烧写流程.其中一般u-boot的烧写流程可分为几类:第一:通过编程器芯片直接烧写:第二通过RVDS ...

  8. Python开发【笔记】:如何在字典遍历中删除key值?

    数据遍历时不能犯傻系列 前言: 针对字典做一些操作时,有时会遇到下面的状况,列如我们需要把data中的key值根据replace中的映射关系进行替换(Caller替换为caller) data = { ...

  9. 用 chown 和 chmod 修改目录所属用户及权限

    1.修改 tmp 目录所属用户为 root,用户组为 root chown -R root:root /tmp12.修改 tmp 目录为可写权限 chmod -R 777 /tmp

  10. 深入理解Docker容器执行引擎runC

    1 简介 根据官方的定义:runC是一个根据OCI标准创建并运行容器的CLI tool. Docker就是基于runC创建的,简单地说,runC就是docker中最为核心的部分,容器的创建,运行,销毁 ...