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 ...
随机推荐
- 由于簇计数比预计的高,格式化操作无法完成——Allocation Unit Size Adjustments for Larger NTFS Volumes.
Allocation Unit Size Adjustments for Larger NTFS Volumes. Problem: When trying to format a new vol ...
- 关于java.lang.ClassNotFoundException
关于java.lang.ClassNotFoundException,在自己的程序中,也出现过好几次了,每次找到原因之后,又会发觉原来是以前处理过的. java.lang.ClassNotFoundE ...
- 在.net中使用redis(StackExchange.Redis)
本文介绍如何在.net中使用redis 安装 代码使用 StackExchange.Redis基础使用 StackExchange.Redis中的事务 安装(windows平台) 安装Chocolat ...
- SUSE 开启ssh、telnet
SSH 1. /etc/ssh/sshd_config [SSH的配置文件] 2. SuSEfirewall2 stop #关闭防火墙 如图,输入命令 vi /etc/ssh/sshd_config ...
- 设置mysql表名大小写不敏感
在跨平台的程序设计中要注意到mysql的一些系统变量在windows和linux上的缺省值是不同的, 比如mysql表名称的大小写变量. 在windows上lower_case_table_names ...
- 10-28SQLserver基础--数据库管理器(基础操作)
C#基础--数据库(用来存储大量的数据) 操作数据库文件唯一途径 SQL server,结构化查询语言简称SQL. Analysis services:分析挖掘数据 Reporting service ...
- URL与HTTP介绍
一.URL 1.基本介绍 URL的全称是Uniform Resource Locator(统一资源定位符) 通过1个URL,能找到互联网上唯一的1个资源 URL就是资源的地址.位置,互联网上的每个资源 ...
- 通过XmlSerializer接口来生成xml文件
xml文件我们可以用来保存一些数据.例如用来备份短信.这个例子中,我们就用XmlSerializer接口来实现一个备份短信的程序.当然了,为了程序简单化,这个程序我们并不是真的去备份短信.我们通过一个 ...
- spirngmvc整合mybatis实现CRUD
一.建立一张简单的User表 CREATE TABLE `users` ( `id` ) NOT NULL AUTO_INCREMENT, `name` ) NOT NULL, `age` ) DEF ...
- mysql的安装以及简单的命令符
在百度当中输入mySQL就可以下载了. 我们只需要一路的点击next就好了,注意,我们在安装的过程当中它会问我们是否要安装路径,我么要选择是. 在显示安装完成之后呢,我们会看到一个复选框,上面写着是否 ...