zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    python中的归并排序
    使用委派取代继承
    ffmpeg 2.3版本号, 关于ffplay音视频同步的分析
    Java学习之路(转)
    怎样通过terminal得到AWS EC2 instance的ip
    让面试官对你“一见钟情”
    Html5 中获取镜像图像
    架构师速成6.3-设计开发思路
    【转】Android的权限permission
    【转】 Android 基于google Zxing实现对手机中的二维码进行扫描--不错
  • 原文地址:https://www.cnblogs.com/tingtin/p/9363364.html
Copyright © 2011-2022 走看看