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 ...
随机推荐
- springboot或者jetty等启动服务器后,如何去停止这个服务
首先在win7下找到运行,但是win7的运行不像XP那么好找,win7运行的位置在:开始→所有程序→附件→运行. 然后在对话框中,输入cmd(大小写均可). 然后是如何查看80端口的方法,一般 ...
- AngularJS:模块
ylbtech-AngularJS:模块 1.返回顶部 1. AngularJS 模块 模块定义了一个应用程序. 模块是应用程序中不同部分的容器. 模块是应用控制器的容器. 控制器通常属于一个模块. ...
- Jenkins构建触发器定时Poll SCM、Build periodically
一.时间设置语法 时间设置由5位组成:* * * * * 第一位:表示分钟,取值0-59. 第二位:表示小时,取值0-23. 第三位:表示日期,取值1-31. 第四位:表示月份,取值1-12. 第五位 ...
- 2015.1.4 判断鼠标点击DataGridView的第几行还是空白处
public int GetRowIndexAt(int mouseLocation_Y) { if (dvaw.FirstDisplayedScrollingRowIndex < 0) { r ...
- SUSE eth0 No such device
删除 etc/udev/rules.d/70-persistent-net.rules 文件 之后重启让系统重新生成eth0配置文件 rm -f etc/udev/rules.d/70-persis ...
- python读取配置文件 ConfigParser
Python 标准库的 ConfigParser 模块提供一套 API 来读取和操作配置文件. 配置文件的格式 a) 配置文件中包含一个或多个 section, 每个 section 有自己的 opt ...
- 通过id查询出图片
第一步,model中需要如下的做法 [UIHint("Picture")] //加上之后会默认显示上传图片的模式 public int PictrueId { get; set; ...
- Python垃圾回收机制:gc模块
在Python中,为了解决内存泄露问题,采用了对象引用计数,并基于引用计数实现自动垃圾回收. 由于Python 有了自动垃圾回收功能,就造成了不少初学者误认为不必再受内存泄漏的骚扰了.但如果仔细查看一 ...
- 偏好设置(Preference)
一.Preference简介 (1)偏好设置是专门用来保存应用程序的配置信息的, 一般情况不要在偏好设置中保存其他数据.如果利用系统的偏好设置来存储数据, 默认就是存储在Library/Prefere ...
- HADOOP HDFS BALANCER介绍及经验总结(转)
1.集群执行balancer命令,依旧不平衡的原因是什么?该如何解决? 2.尽量不在NameNode上执行start-balancer.sh的原因是什么? 集群平衡介绍 Hadoop的HDFS集群非常 ...