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. element.style{}

    有时在写css样式,并调试时,会出现很不可思议的现象,比如:我们定义了一个<div class=”aaa”></div>,在css中定义样式,.aaa{width:500px; ...

  2. EUI组件之CheckBox

    一.CheckBox常规使用 拖动一个checkBox到exml即可 点击效果 二.代码中监听事件 /** * 主页场景 * @author chenkai 2018/5/26 */ class Ho ...

  3. fluentValidation集成到autofac

    废话不说直接上代码 // 首先实现ValidatorFactory public class DependencyResolverValidatorFactory : ValidatorFactory ...

  4. [C/C++] String Reverse 字符串 反转

    #include <iostream> #include <string> #include <algorithm> #include <cstring> ...

  5. ThinkPHP的增删改查!

    对表的操作: 增加:M('表名')->add($data);  (可以是数组) 删除:M('表名')->delete($data); (不可以是数组,删除多个有另外的方法) 修改:M('表 ...

  6. 【事件流】浅谈事件冒泡&&事件捕获------【巷子】

    首先在扯淡的时候我们需要先了解一个东西,这个东西就是事件流. 1.什么是事件流? 解释:当一个HTML元素触发一个事件处理函数的时候,该事件会在该元素节点到根节点之间传播,传播路径所经过的节点都会接受 ...

  7. 170713、springboot编程之多数据源切换

    我们在开发过程中可能需要用到多个数据源,我们有一个项目(MySQL)就是和别的项目(SQL Server)混合使用了.其中SQL Server是别的公司开发的,有些基本数据需要从他们平台进行调取,那么 ...

  8. Pandas介绍

    pandas是python非常好用的一个数据结构包,包含有许多数据操作的方法,能够让你快速简便的提取和保存数据,节省你在这块的数据流操作耗时,从而让你更加专注于逻辑的设计和算法的设计.很多算法的相关库 ...

  9. State of the official Elasticsearch Java clients

    Elasticsearch Java Clients | Elastic https://www.elastic.co/blog/state-of-the-official-elasticsearch ...

  10. asymmetric cryptographic algorithm

    https://baike.baidu.com/item/非对称加密算法/1208652?fr=aladdin 主要算法 编辑 RSA.Elgamal.背包算法.Rabin.D-H.ECC(椭圆曲线加 ...