ACM-ICPC 2018徐州 I题 Rikka with Sorting Networks(搜索)

ACM-ICPC 2018徐州地区的问题,涉及排序网络和几乎有序排列的概念。给定比较排序器的数量,求解满足经过这些排序器后形成至少长度为n-1递增子序列的排列总数,输出结果对一个质数取模。
摘要由CSDN通过智能技术生成

I. Rikka with Sorting Networks

time limit per test

4.0 s

memory limit per test

1024 MB

input

standard input

output

standard output

Rikka knows that Bubble sort is a simple but beautiful algorithm, Quicksort is a complex but efficient algorithm, and Shellsort is a weird but practical algorithm. Rikka is interested in all sorting algorithms and she can assign as many new problems for ICPC contests as she wants.

Rikka hates those guys who create new problems with the same ideas over and over again, and she hopes not to become the person she hates to be. Though she has already assigned several problems for sorting algorithms such as Merge sort and Insertion sort, she decides to show you the last problem about sorting algorithms to end this series forever.

Here Rikka introduces the sorting network and she defines a comparator at first. For a permutation AA of the nn smallest positive integers denoted by a1,a2,⋯,ana1,a2,⋯,an, a comparator [u,v][u,v] (u≠vu≠v) sorts the uu-th and the vv-th element in AA into nondecreasing order. Formally, a comparator is a mapping [u,v][u,v] satisfying

  • [u,v](au)=min(au,av)[u,v](au)=min(au,av); and
  • [u,v](av)=max(au,av)[u,v](av)=max(au,av); and
  • [u,v](ak)=ak[u,v](ak)=ak for all kk with k≠uk≠u and k≠vk≠v.

Rikka defines a sorting network as a composition of comparators and provides for you a sorting network with kk ordered comparators. Now, Rikka wants you to count the number of permutations of 11 to nn which,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值