题目大意:

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

思路:

显然题目要求的是构成下凸函数的概率。

将所有数排序,考虑最小值在中间,往两遍加数。

\(f[i][j][k][l]\)表示左边第一个数是\(i\),左边第二个数是\(j\),右边第一个数是\(k\),右边第二个数是\(l\)的方案数。对于每个状态,枚举新增的数放左边或右边即可。

注意特殊处理一开始的边界情况。

时间复杂度\(\mathcal O(n^4)\)。

源代码:

#include<cstdio>
#include<cctype>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
typedef long long int64;
const int N=61,mod=1e9+7;
int a[N],f[N][N][N][N];
int main() {
int n=getint();
for(register int i=1;i<=n;i++) a[i]=getint();
std::sort(&a[1],&a[n]+1);
int cnt=0;
for(register int i=1;i<=n&&a[i]==a[1];i++) cnt++;
for(register int i=cnt;i<=n;i++) a[i-cnt+1]=a[i];
a[0]=a[1];
n-=cnt-1;
for(register int i=f[1][0][1][0]=1;i<=cnt;i++) {
f[1][0][1][0]=(int64)f[1][0][1][0]*i%mod;
}
for(register int i=1;i<n;i++) {
for(register int j=0;j<i;j++) {
for(register int k=1;k<n;k++) {
for(register int l=0;l<k;l++) {
const int t=std::max(i,k)+1;
if(a[i]*2<=a[t]+a[j]) {
(f[t][i][k][l]+=f[i][j][k][l])%=mod;
}
if(a[k]*2<=a[t]+a[l]) {
(f[i][j][t][k]+=f[i][j][k][l])%=mod;
}
}
}
}
}
int ans=0;
for(register int i=0;i<=n;i++) {
for(register int j=0;j<=n;j++) {
for(register int k=0;k<=n;k++) {
for(register int l=0;l<=n;l++) {
if(i==n||j==n||k==n||l==n) {
(ans+=f[i][j][k][l])%=mod;
}
}
}
}
}
printf("%d\n",ans);
return 0;
}

[HihoCoder1596]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 1596 : Beautiful Sequence

    Description Consider a positive integer sequence a[1], ..., a[n] (n ≥ 3). If for every 2 ≤ i ≤ n-1, ...

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

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

  5. CodeForces 544A

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

  6. cf 403 D

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

  7. CF Set of Strings

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

  8. F - Set of Strings

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

  9. Codeforces Round #302 (Div. 2) A. Set of Strings 水题

    A. Set of Strings Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/pr ...

随机推荐

  1. python模块-platform

    #author:Blood_Zero #coding:utf- import platform print dir(platform) #获取platform函数功能 platform.archite ...

  2. 无需登录-悟空CRM 存储型XSS

    无需登录-悟空CRM 存储型XSS 审计悟空的缘由是看见某云爆出CRM的getshell,于是就想着去挖出来瞅瞅!但可能自己把自己给局限了,就想着去挖那些无限制访问的文件. 故事的发生点 漏洞文件:/ ...

  3. c# CTS 基础数据类型笔记

    C#中的基础数据类型并没有内置于c#语言中,而内置于.net freamework. C#有15个预定义类型,其中13个是值类型,两个是引用类型(string和object) 一.值类型 值类型 数据 ...

  4. Python构造方法、析构方法和单例模式

    一.__init__()方法 __init__()通常在初始化一个类实例的时候调用,如: class Student(object): def __init__(self,name,age): sel ...

  5. 工作常用shell集合

    <1>日志回滚案例======>[root@localhost test]# cat hbase.sh hbase_rotate_log ()       {    log=$1;  ...

  6. Owin WebApi版本控制

    public class WebApiControllerSelector : IHttpControllerSelector { private const string NamespaceKey ...

  7. Python 安装requests模块

    window下安装: 注:不要使用 easy_install requests 命令 这种方式安装后不能卸载,建议使用pip 方法 1.自动安装 输入cmd命令进入命令行窗口,执行 pip insta ...

  8. java容器---Comparable & Comparator

    1.接口Comparable<T> API    参数类型:T ---可以与此对象进行比较的那些对象的类型 此接口强行对实现它的每个类的对象进行整体排序.这种排序被称为类的自然排序,类的c ...

  9. R vs Python:构建data.frame、读取csv与统计描述

    一.Python 数据框就是典型的关系型数据库的数据存储形式,每一行是一条记录,每一列是一个属性,最终构成表格的形式,这是数据科学家必须熟悉的最典型的数据结构. 1.构建数据框 import pand ...

  10. Java输出文件到本地(输出流)

    package cn.buaa; import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; im ...