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\n",ans[i]);
56      }
57      return  0;
58 }

 

转载于:https://www.cnblogs.com/tingtin/p/9363364.html

内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问题中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值