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 ...
随机推荐
- 【BZOJ5082】弗拉格 矩阵乘法
[BZOJ5082]弗拉格 Description “如果明天进了面试,我就去爆妹子的照”——有妹子的丁相允作为一个oier,自然不能立太多flag,让我们来看一道和flag有关的题目吧 给你n个fl ...
- 微信小程序 --- 获取设备信息
获取设备信息: wx.getSystemInfo model:手机型号 pixelRatio:设备像素比 windowWidth:窗口宽度 windowHeight:窗口高度 language:语言 ...
- 沈阳网络赛J-Ka Chang【分块】【树状数组】【dfs序】
Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero point. Then, ...
- opencv学习笔记——Scalar数据结构的理解
首先看一下Scalar的定义 typedef struct Scalar { ]; }Scalar; 可以看到,Scalar是一个由长度为4的数组作为元素构成的结构体,Scalar最多可以存储四个值, ...
- Oracle Schema Objects——PARTITION
Oracle Schema Objects 表分区 表- - 分区( partition )TABLE PARTITION 一段时间给出一个分区,这样方便数据的管理. 可以按照范围range分区,列表 ...
- talib 中文文档(九):# Volatility Indicator Functions 波动率指标函数
Volatility Indicator Functions 波动率指标函数 ATR - Average True Range 函数名:ATR 名称:真实波动幅度均值 简介:真实波动幅度均值(ATR) ...
- Celery和Rabbitmq自学
异步消息队列,也能用于定时和周期性任务.每次修改的task代码还要重启worker,这个有点麻烦 所有带task()装饰器的可调用对象(usertask)都是celery.app.task.Task类 ...
- 解决redis远程连接不上的问题
解决redis远程连接不上的问题 redis现在的版本开启redis-server后,redis-cli只能访问到127.0.0.1,因为在配置文件中固定了ip,因此需要修改redis.conf(有的 ...
- mysql误删表,无备份
mysql误删表,无备份 1.操作步骤:https://blog.csdn.net/u011277123/article/details/78018513?tdsourcetag=s_pctim_ai ...
- Mysql5.6主从复制
搭建(192.168.1.10 -> 192.168.1.20) 1 master 上执行 阻塞 DMLflush tables with read lock; 记录 File 和 Positi ...