CSU 1968 Permutation Descent Counts
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的更多相关文章
- Permutation Descent Counts(递推)
1968: Permutation Descent Counts Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb ...
- Codeforces 818B Permutation Game
首先看一下题目 B. Permutation Game time limit per test 1 second memory limit per test 256 megabytes input s ...
- [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 ...
- 567. Permutation in String判断某字符串中是否存在另一个字符串的Permutation
[抄题]: Given two strings s1 and s2, write a function to return true if s2 contains the permutation of ...
- 几种梯度下降方法对比(Batch gradient descent、Mini-batch gradient descent 和 stochastic gradient descent)
https://blog.csdn.net/u012328159/article/details/80252012 我们在训练神经网络模型时,最常用的就是梯度下降,这篇博客主要介绍下几种梯度下降的变种 ...
- SPOJ - PERMJUMP Permutation Jumping
Discription John likes playing the game Permutation Jumping. First he writes down a permutation A of ...
- [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 ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Palindrome Permutation II 回文全排列之二
Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...
随机推荐
- 如何学习 cocos2d-x ?
发表于 04/23/2014 作者 zrong — 24 条评论 ↓ 11,687 次查看 本站文章除注明转载外,均为本站原创或者翻译. 本站文章欢迎各种形式的转载,但请18岁以上的转载者注明文章出处 ...
- Listview Section 多个标题以及内容
其中日期标题部分视图布局: 带图片的条目布局部分: 问题在于,如何在ListView中既有标题条目又有内容条目. 这里用到了设计模式中的Iterator模式.在java代码中示例有Iterator,可 ...
- 拼接的html的onclick事件中无法传递对象给js方法的处理办法
如下: 拼接的html: " onclick=\"valDocName2('"+JSON.stringify(doc).replace(new RegExp(" ...
- java启动3个线程轮流打印数字
转自:http://blog.csdn.net/u014011112/article/details/50988769 http://blog.csdn.net/perrywork/article/d ...
- EF批量添加,删除,修改的扩展
在EF各版本中,没有相应批量的添加,删除,修改,在用ORM 处理数据时直有个尴尬.在网上,也接到了很多网友的询问这方面的情况,特此今天把这方面的相关扩展分享一下,(这里只做批量删除的例子,添加和修改的 ...
- vue - 准备知识
一.知识 http://www.cnblogs.com/majj/https://www.cnblogs.com/majj/category/1216624.html 阮一峰 es6http://es ...
- ThinkPhp3.2.3 多项目 后台 APP接口设计 框架设计
↓↓↓项目文件组成部分↓↓↓ APP文件是后台,index.php是入口文件 Interface文件是接口,注意这里不要用api命名!可能会有问题!interface.php是入口文件 注:两个入口文 ...
- python 的 import 使用规则
对于含有 __init__.py 的目录(如adir),其实它就是一个package,它的子目录如果也包含 __init__.py,则只要将 adir 加入 sys.path,则它的字目录就不用加了, ...
- Openstack(二)基本环境准备--网络、时间、yum源等
2.1服务器版本安装 2.1.1服务器使用:centos7.4 + vm12 2.1.2重命名网卡: 传递内核参数 net.ifnames=0 biosdevname=0,以更改网卡名称为eth0,e ...
- POJ2891:Strange Way to Express Integers(解一元线性同余方程组)
写一下自己的理解,下面附上转载的:若a==b(modk);//这里的==指的是同余,我用=表示相等(a%k=b)a-b=kt(t为整数)以前理解的错误思想:以前认为上面的形式+(a-tb=k)也是成立 ...