• B Array


    •  65536K
     动态归化+滚动数组

    JSZKC is the captain of the lala team.

    There are NN girls in the lala team. And their height is [1,N][1,N] and distinct. So it means there are no two girls with a same height.

    JSZKC has to arrange them as an array from left to right and let h_ihi be the height of the i^{th}ith girl counting from the left. After that, he can calculate the sum of the inversion pairs. A inversion pair counts if h_i>h_jhi>hj with i<ji<j.

    Now JSZKC wants to know how many different arranging plans with the sum of the inversion pairs equaling KK. Two plans are considered different if and only if there exists an ii with h_ihi different in these two plans.

    As the answer may be very large, you should output the answer mod 10000000071000000007.

    Input Format

    The input file contains several test cases, each of them as described below.

    • The first line of the input contains two integers NN and K(1 le N le 5000,0 le K le 5000)(1N5000,0K5000), giving the number of girls and the pairs that JSZKC asked.

    There are no more than 50005000 test cases.

    Output Format

    An integer in one line for each test case, which is the number of the plans mod 10000000071000000007.

    样例输入

    3 2
    3 3

    样例输出

    2
    1

    题目来源

    The 2018 ACM-ICPC China JiangSu Provincial Programming Contest

     

     

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 #include <algorithm>
     6 #include <utility>
     7 #include <vector>
     8 #include <map>
     9 #include <queue>
    10 #include <stack>
    11 #include <cstdlib>
    12 typedef long long ll;
    13 #define lowbit(x) (x&(-x))
    14 #define ls l,m,rt<<1
    15 #define rs m+1,r,rt<<1|1
    16 using namespace std;
    17 const ll mod=1e9+7;
    18 const int N=5500;
    19 int ans[N],dp[2][N];
    20 int cnt=0,ret=0;
    21 struct Node{
    22     int id,n,k;
    23     bool operator <(const Node&a)const{
    24         return n<a.n;
    25     }
    26 }node[N];
    27 int main()
    28 {
    29      while(~scanf("%d%d",&node[cnt].n,&node[cnt].k)){
    30          //if(node[cnt].n==4)  break;
    31          node[cnt].id=cnt;        
    32         cnt++;
    33         
    34      }
    35      //cout<<cnt<<endl;
    36      sort(node,node+cnt);//i在增加,一定先处理n小的。
    37      dp[0][0]=1;
    38      for(int i=1;i<=5000;i++){
    39          int sum=0;//每一次只和前一次有关,因此sum每次都要清0
    40          for(int j=0;j<=5000;j++){
    41              sum=(sum+dp[i-1&1][j])%mod;
    42              if(j-i>=0)  sum=(sum-dp[i-1&1][j-i]+mod)%mod;//j增大时,区间右移,因此不断减
    43             // j-i>=0   是不需要加入的。 
    44             // j-(i-1)    到  j-0是需要加入的。         
    45              dp[i&1][j]=sum;
    46          }
    47          // 借用j的增加间接的从 j-(i-1)到 j-0
    48          //i固定了,0到i-1 的区间 长度也就固定了。
    49          while(ret<cnt&&node[ret].n==i){
    50              ans[node[ret].id]=dp[i&1][node[ret].k];
    51              ret++;
    52          }
    53      }
    54      for(int i=0;i<cnt;i++){
    55          printf("%d
    ",ans[i]);
    56      }
    57      return  0;
    58 }
  • 相关阅读:
    Unity WebGL MoonSharp崩溃问题
    UISprite(NGUI)扩展 图片镂空
    自动化交易机器人Beta猪
    如何成为一个真正在路上的Linuxer
    课堂里学不到的C与C++那些事(一)
    Android ART运行时与Dalvik虚拟机
    用Dockerfile构建docker image
    论docker中 CMD 与 ENTRYPOINT 的区别
    sshfs远程文件系统挂载
    docker镜像与容器存储结构分析
  • 原文地址:https://www.cnblogs.com/tingtin/p/9363364.html
Copyright © 2020-2023  润新知