Beautiful Sequence

给定一些数(可能相同),将它们随机打乱后构成凹函数,求概率 。N<=60 。

首先,这种题求概率事实上就是求方案。所以现在要求的是用这些数构成凹函数的方案数。

依稀记得上次的一道考试题,只是把凹函数变成了一个具有特殊性质的单调序列而已。这道题也是一样,由于它不关心数的位置,所以把数排序以后,可以统计把当前数插入凹函数的方案。

exp1:与数的位置无关的计数题可以考虑排序。

用\(f[i][j][k][l]\)表示凹函数最左边的两个点,最右边的两个点。那么新来的一个点要么在最左边,要么在最右边,转移即可。

有人可能会问:怎么维持转移顺序啊。没关系,我们钦定i是最高的点。那么我们可以把第二个转移方程写成\(f[i][j][k][l]->f[i][j][l][i+1]=f[i+1][l][j][i]\)就行了。是不是很妙。

exp2:对于某些状态具有对称性的题,可以考虑把状态的某一维钦定成按顺序转移的维度。这样就好dp了。

#include <cstdio>
#include <algorithm>
using namespace std; const int maxn=62, mod=1e9+7;
int n, b[maxn], a[maxn], m, ans, c;
int f[maxn][maxn][maxn][maxn]; bool ok(int x, int y, int z){ return 2*a[y]<=a[x]+a[z]; }
void up(int &x, int y){ x+=y; if (x>mod) x-=mod; } int main(){
scanf("%d", &n);
for (int i=1; i<=n; ++i) scanf("%d", &b[i]);
sort(b+1, b+n+1); ++c;
for (int i=2; i<=n; ++i) if (b[i]==b[1]) ++c; else break;
for (int i=c; i<=n; ++i) a[++m]=b[i]; n=m;
f[1][1][1][1]=1;
for (int i=1; i<=n; ++i)
for (int j=1; j<=n; ++j)
for (int k=1; k<=n; ++k)
for (int l=1; l<=n; ++l){
if (ok(i+1, i, j)) up(f[i+1][i][k][l], f[i][j][k][l]);
if (ok(i+1, l, k)) up(f[i+1][l][j][i], f[i][j][k][l]);
if (i==n||l==n) up(ans, f[i][j][k][l]);
}
for (int i=1; i<=c; ++i)
ans=(long long)ans*i%mod;
printf("%d\n", ans);
return 0;
}

Beautiful Sequence的更多相关文章

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

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

  2. hihoCoder 1596 : Beautiful Sequence

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

  3. [HihoCoder1596]Beautiful Sequence

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

  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. [置顶] getenv、setenv函数(获取和设置系统环境变量) 与 环境变量

    1.getenv() 函数名: getenv 功 能: 从环境中取字符串,获取环境变量的值 头文件: stdlib.h 用 法:char *getenv(char *envvar); 函数说明:get ...

  2. iOS中的数据存储

    SQLite3 SQLite3是一款开源的嵌入式关系型数据库,可移植性好,易使用,内存开销小. SQLite3是无类型的,意味着你可以保存任何类型的数据到任意表的任意字段中. SQLite3常用的4种 ...

  3. Canopy聚类算法(经典,看图就明白)

    只有这个算法思想比较对,其他 的都没有一开始的remove: 原网址:http://www.shahuwang.com/?p=1021 Canopy Clustering 这个算法是2000年提出来的 ...

  4. 用UltraISO把硬盘文件制作成ISO格式

    转自:https://wenku.baidu.com/view/0052c88dcc22bcd126ff0cbf.html 用UltraISO把硬盘文件制作成ISO格式方法: 制作硬盘ISO文件步骤一 ...

  5. LNMP 1.6 常见的502问题解决

    在nginx上跑discuz,先修改配置文件 cd /usr/local/nginx/conf/vhosts/ vim test.conf server { listen ; server_name ...

  6. [Python Study Notes]七彩散点图绘制

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  7. linux&nbsp;dev/dsp&nbsp;声卡学习笔记

    原文地址:dev/dsp 声卡学习笔记">linux dev/dsp 声卡学习笔记作者:ziyou飞翔       无论是从声卡读取数据,或是向声卡写入数据,事实上都具有特定的格式(f ...

  8. 前端JS面试题

    题目如下: function Foo() { getName = function () { alert (1); }; return this; } Foo.getName = function ( ...

  9. php异步执行函数

    1.在unix系统中,使用popen和pclose可以创建管道(通信途径)来连接到其他程序.   2.能够执行服务器命令的php函数有: exec(commond,$output) 接收一个命令,把得 ...

  10. day17-jdbc 5.url介绍

    url用于标识数据库的位置,用于标识找哪个数据库. 总结:url是路径,其实就是确定是哪个数据库.用来确定我用的是哪一个数据库,并且通知我这个Connection或者是这个DriverManager获 ...