B Array
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 KK (1 \le N \le 5000,0 \le K \le 5000)(1≤N≤5000,0≤K≤5000), 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\n",ans[i]); 56 } 57 return 0; 58 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现