zoukankan      html  css  js  c++  java
  • 51nod1020 逆序排列

    t<=10000个问,每次问n<=1000的全排列中逆序数对为k<=10000个的有多少,mod 1e9+7。

    直接dp,$f(i,j)$--i的全排列中逆序数对为j的有多少,$f(i,j)=sum_{k=max(0,j-i+1)}^{j} f(i-1,k)$,这东西记个前缀和即可n^2。

    然后就没了

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<algorithm>
     4 #include<stdlib.h>
     5 //#include<queue>
     6 //#include<math.h>
     7 //#include<time.h>
     8 //#include<iostream>
     9 using namespace std;
    10 
    11 int t,n,K;
    12 #define maxn 1011
    13 #define maxm 20011
    14 
    15 const int mod=1e9+7;
    16 int f[maxn][maxm];
    17 int main()
    18 {
    19     n=1000,K=20000;
    20     f[1][0]=1;
    21     for (int i=2;i<=n;i++)
    22     {
    23         f[i][0]=1;
    24         for (int j=1,to=min(i*(i-1)/2,K);j<=to;j++)
    25             f[i][j]=((f[i][j-1]+f[i-1][j])%mod-(j>=i?f[i-1][j-i]:0)+mod)%mod;
    26     }
    27     scanf("%d",&t);
    28     while (t--) {scanf("%d%d",&n,&K); printf("%d
    ",f[n][K]);}
    29     return 0;
    30 }
    View Code
  • 相关阅读:
    openmp
    opencv 读写矩阵
    string to const char*
    c++ string to number
    HDU 1520 Anniversary Party
    ZOJ 1003 Crashing Balloon
    HDU 4171 Paper Route
    ZOJ 2067 White Rectangles
    TOJ 1690 Cow Sorting (置换群)
    TOJ 2814 Light Bulb
  • 原文地址:https://www.cnblogs.com/Blue233333/p/8087767.html
Copyright © 2011-2022 走看看