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. Git 建立仓库及常用命令速查表

    Git新建仓库两种模式: 一.项目在本地时,本地初始化仓库并提交至Coding.Net 新建一个空白目录并进入,执行如下流程 1.git init2.项目代码复制到当前目录3.git add *4.g ...

  2. 第1次作业:no blog no fun

    1.先回答老师的问题 第一部分:结缘计算机       读了进入2012 -- 回顾我走过的编程之路后,我试着回顾了我的编程生涯的开始.我最原始的记忆就是老爸教我用电脑玩连连看,那时候的显示器应该是C ...

  3. Argparse简易教程

    Argparse简易教程 原文:Argparse Tutorial 译者:likebeta 本教程是对于Python标准库中推荐使用的命令行解析模块argparse的简单介绍. PS:还有其他两个模块 ...

  4. webView调用系统地图,电话,和跳转链接的方法

    webView.dataDetectorTypes = UIDataDetectorTypePhoneNumber | UIDataDetectorTypeLink | UIDataDetectorT ...

  5. 使用Spark MLlib进行情感分析

    使用Spark MLlib进行情感分析             使用Spark MLlib进行情感分析 一.实验说明 在当今这个互联网时代,人们对于各种事情的舆论观点都散布在各种社交网络平台或新闻提要 ...

  6. js 时间戳 vue 时间戳的转换 ?

    在没有用vue做项目之前 也遇到过戳转换的问题 直接函数 调用 方法 这个也可以写成vue的  把function去掉  formatDate后面加冒号 就可以了 当然这个不是原创 但是是谁的我忘记了 ...

  7. Spring Cache扩展:注解失效时间+主动刷新缓存(二)

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  8. Web Api 过滤器之 AuthorizationFilter 验证过滤器

    该过滤器是最先执行的过滤器,即使把它放在最后 API [MyActionFilter] [MyExceptionFilter] [MyAuthorize] public void Get() { Tr ...

  9. 24.C++- 抽象类(存虚函数)、接口、多重继承

    抽象类和接口 什么是抽象类 用来表示现实世界中的抽象概念 是一种只能定义类型,而不能产生对象的类 只能被子类继承,且抽象类的相关成员函数没有完整的体现,用来被子类重写. 比如图形(Shape)类, 就 ...

  10. python 判断变量是否是 None 的三种写法

    代码中经常会有变量是否为None的判断,有三种主要的写法:第一种是`if x is None`:第二种是 `if not x:`:第三种是`if not x is None`(这句这样理解更清晰`if ...