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. eclipse/myeclipse 中的一些常用的快捷键

    一.eclipse 中的一些常用的快捷键 Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能,能够大大提高开发效率. Eclipse中有如下一些和编辑相关的快捷键. 1. [ALT+/] ...

  2. 详探TextRange对象--查找与选择(转载)

    TextRange对象是动态HTML(DHTML)的高级特性,使用它可以实现很多和文本有关的任务,例如搜索和选择文本.文本范围让您可以选择性的将字符.单词和句子从文档中挑选出来.TextRange对象 ...

  3. Laravel 5.7 No 'Access-Control-Allow-Origin' header is present on the request resource

    前后端项目跨域访问时会遇到此问题,解决方法如下: 创建一个中间件 php artisan make:middleware EnableCrossRequestMiddleware 该中间件的文件路径为 ...

  4. 南京网络赛I-Skr【回文树模板】

    19.32% 1000ms 256000K A number is skr, if and only if it's unchanged after being reversed. For examp ...

  5. spriing boot 启动报错:Cannot determine embedded database driver class for database type NONE

    最近在学习使用spring boot.使用maven创建好工程,只引用需要用到的spring boot相关的jar包,除此之外没有任何的配置. 写了一个最简单的例子,如下所示: package com ...

  6. Python开发【项目】:博客后台

    概述 通过自己写的博客后台代码.思路,来与武sir的代码进行一个差异化的比较,记录之间的差距,改善以后写代码的思路 博客后台这个项目,对之前Django学习的各个知识点都有涉及到,非常重要 用户登录验 ...

  7. render的几个应用

    1.render可以通过模版语法来渲染字符串,例如变量,标签,for循环,这里就不赘述,我就举个自己印象很深刻灵活应用,看看render到底做了什么,关心什么 注意! 在rander眼里,没有html ...

  8. cocos2d 特效

    一.特效概念 特效是让精灵(CCSprite)执行某种特殊的效果.其实,特效也是一种动画! 但是,为什么要把特效与动画区分呢?因为,特效是基于网格属性来进行的. 如何区分动画与特效?简单的将,当使用到 ...

  9. Cocos2d-x学习笔记(17)(TestCpp源代码分析-1)

    TestCpp源代码基于Cocos2d-x2.1.3版本号,部分资源来自红孩儿的游戏编程之路CSDN博客地址http://blog.csdn.net/honghaier/article/details ...

  10. Incorrect datetime value

    今天在开发库上给一个表添加字段时候,发现居然报错: root@DB 06:14:42>ALTER TABLE `DB`.` user` ADD COLUMN `status_mode` TINY ...