Description

Consider a positive integer sequence a[1], ..., a[n] (n ≥ 3). If for every 2 ≤ i ≤ n-1, a[i-1] + a[i+1] ≥ 2 × a[i] holds, then we say this sequence is beautiful.

Now you have a positive integer sequence b[1], ..., b[n]. Please calculate the probability P that the resulting sequence is beautiful after uniformly random shuffling sequence b.

You're only required to output (P × (n!)) mod 1000000007. (Obviously P × (n!) is an integer)

Input

First line contains an integer n. (3 ≤ n ≤ 60)

Following n lines contain integers b[1], b[2], ..., b[n]. (1 ≤ b[i] ≤ 1000000000)

Output

Output (P × (n!)) mod 1000000007.

Sample Input

4
1
2
1
3

Sample Output

8
https://hihocoder.com/problemset/problem/1596dp鬼题
题目条件可化为a[i+1]-a[i]>=a[i]-a[i-1]
考虑排序再做分配
根据分析我们发现最后的高度序列是一个勾函数,先减小后增大
我们讨论b[i-1],b[i],b[i+1]的情况
显然i-1和i+1不可能同时大于i
只可能一个大于i一个小于,或两个都大于
但是两个都大于的情况显然只有一次,两边是不会有的
如5 3 5 1 3 5
那么就出现了两个都小于的情况
那么我们就可以dp
令f[i][j][k][l]表示最左边两个为i,j 最右边两个为k,l
我们先将最小值放入f[1][0][1][0]=1
接下来要放的数为max(i,k)+1,为什么?因为是排过序的,从小到大放就行了
判断是否满足:
a[i+1]-a[i]>=a[i]-a[i-1]
还有一个细节:
当有多个最小值时,显然不能直接dp,以最小值数量为l=3举例
因为直接dp只能得到4种,而实际有6种(此题鬼处)
所以把所有最小值缩为一个,最后乘l!
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int Mod=;
long long f[][][][],a[],p[],tmp,ans;
int n;
int main()
{int i,j,k,l=;
cin>>n;
for (i=;i<=n;i++)
{
scanf("%lld",&a[i]);
}
sort(a+,a+n+);
p[]=;
for (i=;i<=n;i++)
p[i]=(p[i-]*i)%Mod;
for (i=;i<=n;i++)
if (a[i]==a[]) l++;
tmp=p[l];
for (i=;i<=n-l+;i++)
a[i]=a[i+l-];
n=n-l+;
f[][][][]=;
for (i=;i<=n;i++)
{
for (j=;j<=n-;j++)
{
for (k=;k<=n;k++)
{
for (l=;l<=n-;l++)
{
int z=max(i,k)+;
if (z==n+)
{
ans+=f[i][j][k][l];
ans%=Mod;
continue;
}
if (a[z]-a[k]>=a[k]-a[l]||l==)
f[i][j][z][k]+=f[i][j][k][l],f[i][j][z][k]%=Mod;
if (a[z]-a[i]>=a[i]-a[j]||j==)
f[z][i][k][l]+=f[i][j][k][l],f[z][i][k][l]%=Mod;
}
}
}
}
cout<<(ans*tmp)%Mod;
}

hihoCoder 1596 : Beautiful Sequence的更多相关文章

  1. Beautiful Sequence

    Beautiful Sequence 给定一些数(可能相同),将它们随机打乱后构成凹函数,求概率 .N<=60 . 首先,这种题求概率事实上就是求方案.所以现在要求的是用这些数构成凹函数的方案数 ...

  2. Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)

    链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...

  3. hihocoder 1061.Beautiful String

    题目链接:http://hihocoder.com/problemset/problem/1061 题目意思:给出一个不超过10MB长度的字符串,判断是否里面含有一个beautiful strings ...

  4. [HihoCoder1596]Beautiful Sequence

    题目大意: \(n(n\le60)\)个数\(A_{1\sim n}\),将这些数随机打乱,问最后构成的数列满足对于所有的\(2\le i\le n-1\),都有\(2A_i\le A_{i-1}+A ...

  5. Solution -「Gym 102956B」Beautiful Sequence Unraveling

    \(\mathcal{Description}\)   Link.   求长度为 \(n\),值域为 \([1,m]\) 的整数序列 \(\lang a_n\rang\) 的个数,满足 \(\not\ ...

  6. hihoCoder挑战赛31

    #1595 : Numbers 时间限制:8000ms 单点时限:1000ms 内存限制:256MB 描述 给定n个整数常数c[1], c[2], ..., c[n]和一个整数k.现在需要给2k个整数 ...

  7. CodeForces 544A

    You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concat ...

  8. cf 403 D

    D. Beautiful Pairs of Numbers time limit per test 3 seconds memory limit per test 256 megabytes inpu ...

  9. CF Set of Strings

    Set of Strings time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. 《结对-HTML贪吃蛇游戏项目-测试过程》

    项目托管平台地址:https://gitee.com/zhaojianhuiAA/TanChiShe/blob/master/snake.html 项目成员:赵建辉.马壮. 测试: 1.界面:用jav ...

  2. Java Collections API和泛型

    Java Collections API和泛型 数据结构和算法 学会一门编程语言,你可以写出一些可以工作的代码用计算机来解决一些问题,然而想要优雅而高效的解决问题,就要学习数据结构和算法了.当然对数据 ...

  3. Python科学计算(一)

    作者 J.R. Johansson (robert@riken.jp) http://dml.riken.jp/~rob/ 最新版本的 IPython notebook 课程文件 http://git ...

  4. iOS开发之UITextView,设置textViewplaceholder

    一.设置textView的placeholder UITextView上如何加上类似于UITextField的placeholder呢,其实在UITextView上加上一个UILabel或者UITex ...

  5. vue的简单tab

    <!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" ...

  6. 《javascript设计模式与开发实践》阅读笔记(16)—— 状态模式

    状态模式 会区分事物内部的状态,事物内部状态的改变往往会带来事物的行为改变.比如电灯的开关是开还是关,在外界的表现就完全不同. 电灯例子 按照常规思路,实现一个电灯就是构造一个电灯类,然后指定一下它的 ...

  7. LeetCode & Q414-Third Maximum Number-Easy

    Array Math Description: Given a non-empty array of integers, return the third maximum number in this ...

  8. mySql一个字段的值模糊匹配多表多列的查询

    1.dao层/** * 分页查询点卡集合信息 * @param tid 游戏类型编号 * @param gid 游戏编号 * @param searchInfo 包括(点卡名称,游戏名称,点卡面值,游 ...

  9. redis入门(14)redis集群下的数据分区存储

    redis入门(10)redis集群下的数据分区存储

  10. MySQL8.0 原子DDL

    Edit MySQL8.0 原子DDL 简介 MySQL8.0 开始支持原子 DDL(atomic DDL),数据字典的更新,存储引擎操作,写二进制日志结合成了一个事务.在没有原子DDL之前,DROP ...