Beautiful Sequence
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的更多相关文章
- Codeforces Round #604 (Div. 2) D. Beautiful Sequence(构造)
链接: https://codeforces.com/contest/1265/problem/D 题意: An integer sequence is called beautiful if the ...
- hihoCoder 1596 : Beautiful Sequence
Description Consider a positive integer sequence a[1], ..., a[n] (n ≥ 3). If for every 2 ≤ i ≤ n-1, ...
- [HihoCoder1596]Beautiful Sequence
题目大意: \(n(n\le60)\)个数\(A_{1\sim n}\),将这些数随机打乱,问最后构成的数列满足对于所有的\(2\le i\le n-1\),都有\(2A_i\le A_{i-1}+A ...
- Solution -「Gym 102956B」Beautiful Sequence Unraveling
\(\mathcal{Description}\) Link. 求长度为 \(n\),值域为 \([1,m]\) 的整数序列 \(\lang a_n\rang\) 的个数,满足 \(\not\ ...
- CodeForces 544A
You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concat ...
- cf 403 D
D. Beautiful Pairs of Numbers time limit per test 3 seconds memory limit per test 256 megabytes inpu ...
- CF Set of Strings
Set of Strings time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- F - Set of Strings
You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concat ...
- 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 ...
随机推荐
- UVA548(二叉树遍历)
You are to determine the value of the leaf node in a given binary tree that is the terminal node of ...
- 【转】 Pro Android学习笔记(七八):服务(3):远程服务:AIDL文件
目录(?)[-] 在AIDL中定义服务接口 根据AIDL文件自动生成接口代码 文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.n ...
- Winsock 示例
#include "stdafx.h" #include <Windows.h> #include <iostream> #pragma comment(l ...
- java 多线程系列基础篇(十一)之生产消费者问题
1. 生产/消费者模型 生产/消费者问题是个非常典型的多线程问题,涉及到的对象包括“生产者”.“消费者”.“仓库”和“产品”.他们之间的关系如下:(01) 生产者仅仅在仓储未满时候生产,仓满则停止生产 ...
- eclipse 报错:GC overhead limit exceeded
还是eclipse内存问题 修改eclipse.ini -Xms512m -Xmx1024m 必要的情况下, 添加 -XX:MaxPermSize=1024M 表示在编译文件时一直占有最大内存
- c++对象模型探索(一)
粗略阅读了<深度探索c++对象模型>一书后,对c++对象底层的内存布局有了一些了解,但同时,也产生了一些疑惑: 1.将子类指针用dynamic_cast转成父类指针之后,其虚表指针会相应变 ...
- dos 下bat命令
注:cmd下 help > result.txt assoc 显示或修改文件扩展名关联. attrib 显示或更改文件属性. break 设置或清除扩展式 ctrl+c 检查. bcded ...
- 利用powerdesigner创建表模型后导出sql语句方法,以及报错 Generation aborted due to errors detected during the verification of the model.的解决办法
今天用powerdesigner建了表模型,下面先说一下导出sql语句的步骤. 1.选项 2. 然后就报错了,下面说解决办法,很简单. 你没看错,把模型检查的√去掉就行了~~ 导出表名不带双引号的设置 ...
- springmvc 注解扫描失败的可能原因
情况是这样的:web工程采用了ssm框架,dao和service都是通过annotation方式注入的,工程运行正常.后来把service和dao打成jar放在工程的lib目录下,问题来了,配置没改动 ...
- 使用R语言绘制图表
#========================================================#wolf moose graph version 20170616.R###Data ...