题目大意:

\(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 socket编程入门级

    客户端 import socket import time sk = socket.socket() # 第一步:创建socket对象 address = ('127.0.0.1', 8080) # ...

  2. word文档下划线无法显示的解决方法

    在编辑文档的时候经常会遇到下划线无法显示的情况,如图: 如果遇到不能在姓名后面加下划线的情况,我们该怎么做? 请看下面的图解: 1.首先点击左上角的office图标 2.点击右下角“word选项” 3 ...

  3. Prepare tasks for django project deployment.md

    As we know, there are some boring tasks while deploy Django project, like create db, do migrations a ...

  4. 四、springcloud之服务调用Feign(二)

    一.Fegin的常见应用 Feign的Encoder.Decoder和ErrorDecoder Feign将方法签名中方法参数对象序列化为请求参数放到HTTP请求中的过程,是由编码器(Encoder) ...

  5. 纯css进度条,各种兼容

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD&g ...

  6. maven scope 'provided' 和 ‘compile’的区别

    解释 其实这个问题很简单. 对于scope=compile的情况(默认scope),也就是说这个项目在编译,测试,运行阶段都需要这个artifact(模块)对应的jar包在classpath中. 而对 ...

  7. SQL中EXCEPT和Not in的区别?

    初始化两张表: CREATE TABLE tb1(ID int) INSERT tb1          SELECT NULLUNION  ALL          SELECT NULLUNION ...

  8. Effective STL 笔记 -- Item 6 ~ 7: Container and Object Pointer

    Effective STL 笔记 – Item 6 ~ 7: Container and Object Pointer 中间两次笔记被删掉了,简单补一下: Item 3 中提到如果将对象直接放入容器中 ...

  9. Java字符串常见实例与函数

    字符串比较 字符串函数 compareTo (string) ,compareToIgnoreCase(String) 及 compareTo(object string) 来比较两个字符串,并返回字 ...

  10. easyui tree tabs

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