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. svn-clearup 报错的处理(Cleanup failed to process the following paths...)

    在使用 svn 客户端执行操作失败后,执行 Clean up 操作也报错:Cleanup failed to process the following paths... ,一直不知道是什么原因.通常 ...

  2. 机器学习:集成学习(集成学习思想、scikit-learn 中的集成分类器)

    一.集成学习的思想 集成学习的思路:一个问题(如分类问题),让多种算法参与预测(如下图中的算法都可以解决分类问题),在多个预测结果中,选择出现最多的预测类别做为该样本的最终预测类别: 生活中的集成思维 ...

  3. Oracle 数据库表(常见的表)

    数据库表(常见的表) 堆组织表:普通表 索引组织表:iot 嵌套表 临时表 外部表 1 表 一个表最多1000列,oracle会把列大于254的行存储在多个单独的行段中, 表中的行是无限的,    术 ...

  4. linux串口基本编程

    Linux的串口表现为设备文件.Linux的串口设备文件命名一般为/dev/ttySn(n=0.1.2„„),若串口是USB扩展的,则串口设备文件命名多为/dev/ttyUSBn(n=0.1.2„„) ...

  5. 第十七章 Velocity优化实践(待续)

    现实存在的问题 优化的理论基础 一个高效的模版引擎实现思路 优化成果 其他优化手段

  6. CSS3图片以中心缩放,放大超出隐藏实现

    首页,重点是有一个包裹img标签的容器,这里我们给该容器设置一个class为selfScale <div class="selfScale"> <img sr=& ...

  7. SpringMVC工作原理图解

    SpringMVC的工作原理图: SpringMVC流程 1.  用户发送请求至前端控制器DispatcherServlet. 2.  DispatcherServlet收到请求调用HandlerMa ...

  8. C#理解泛型(源代码)及 default(T)

    1.类型不安全.且代码无法遍历重用的源代码. 2.泛型源代码 源代码下载: http://files.cnblogs.com/files/qqhfeng/ConsoleApplication1.rar

  9. UIView显示原理和过程

    一.UIView显示原理         一个控件,UIView之所以可以显示,是因为内部在UIView的内部有一个layer属性作为根图层,根图层上可以放其他子图层,在UIView中所有能够看到的内 ...

  10. Spring装配各种类型bean

    一.单属性值的装配 //setter注入,提供无参构造器,提供setXX方法 <property name="" value=""></pro ...