[HihoCoder1596]Beautiful Sequence
题目大意:
\(n(n\le60)\)个数\(A_{1\sim n}\),将这些数随机打乱,问最后构成的数列满足对于所有的\(2\le i\le n-1\),都有\(2A_i\le A_{i-1}+A_{i+1}\)的概率。
思路:
显然题目要求的是构成下凸函数的概率。
将所有数排序,考虑最小值在中间,往两遍加数。
\(f[i][j][k][l]\)表示左边第一个数是\(i\),左边第二个数是\(j\),右边第一个数是\(k\),右边第二个数是\(l\)的方案数。对于每个状态,枚举新增的数放左边或右边即可。
注意特殊处理一开始的边界情况。
时间复杂度\(\mathcal O(n^4)\)。
源代码:
#include<cstdio>
#include<cctype>
#include<algorithm>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
typedef long long int64;
const int N=61,mod=1e9+7;
int a[N],f[N][N][N][N];
int main() {
int n=getint();
for(register int i=1;i<=n;i++) a[i]=getint();
std::sort(&a[1],&a[n]+1);
int cnt=0;
for(register int i=1;i<=n&&a[i]==a[1];i++) cnt++;
for(register int i=cnt;i<=n;i++) a[i-cnt+1]=a[i];
a[0]=a[1];
n-=cnt-1;
for(register int i=f[1][0][1][0]=1;i<=cnt;i++) {
f[1][0][1][0]=(int64)f[1][0][1][0]*i%mod;
}
for(register int i=1;i<n;i++) {
for(register int j=0;j<i;j++) {
for(register int k=1;k<n;k++) {
for(register int l=0;l<k;l++) {
const int t=std::max(i,k)+1;
if(a[i]*2<=a[t]+a[j]) {
(f[t][i][k][l]+=f[i][j][k][l])%=mod;
}
if(a[k]*2<=a[t]+a[l]) {
(f[i][j][t][k]+=f[i][j][k][l])%=mod;
}
}
}
}
}
int ans=0;
for(register int i=0;i<=n;i++) {
for(register int j=0;j<=n;j++) {
for(register int k=0;k<=n;k++) {
for(register int l=0;l<=n;l++) {
if(i==n||j==n||k==n||l==n) {
(ans+=f[i][j][k][l])%=mod;
}
}
}
}
}
printf("%d\n",ans);
return 0;
}
[HihoCoder1596]Beautiful Sequence的更多相关文章
- Beautiful Sequence
Beautiful Sequence 给定一些数(可能相同),将它们随机打乱后构成凹函数,求概率 .N<=60 . 首先,这种题求概率事实上就是求方案.所以现在要求的是用这些数构成凹函数的方案数 ...
- 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, ...
- 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 ...
随机推荐
- plsql链接数据库配置
一. 目录结构 D:\install\PLSQL |-- instantclient_11_2 |-- tnsnames.ora |-- PLSQL ...
- css给表格每一列设置不同的样式
第一列#id table tr td:first-child{ overflow: visible; }第二列table tr td:first-child+td{color:#666;}第三列tab ...
- 如何基于Spring Boot搭建一个完整的项目
前言 使用Spring Boot做后台项目开发也快半年了,由于之前有过基于Spring开发的项目经验,相比之下觉得Spring Boot就是天堂,开箱即用来形容是绝不为过的.在没有接触Spring B ...
- aarch64_fc26_url
http://linux.yz.yamagata-u.ac.jp/pub/linux/fedora-projects/fedora-secondary/releases/26/Everything/a ...
- Kettle进行数据迁移(ETL)
由于开发新的系统,需要将之前一个老的C/S应用的数据按照新的数据设计导入到新库中.此过程可能涉及到表结构不一致.大数据量(千万级,甚至上亿)等情况,包括异构数据的抽取.清洗等等工作.部分复杂的工作需要 ...
- unity 优秀开源项目
ihaiu.GUIDRef (查看项目资源使用情况) http://blog.ihaiu.com/unity-GUIDRef Ihaiu.PoolManager (对象池) http://github ...
- 关于Eclipse连接sql server 2008的若干问题
以下内容转自:https://www.cnblogs.com/skylarzhan/p/7619977.html Eclipse中使用SQL server 2008数据库 一.准备材料 要能够使用数据 ...
- C++之可调用对象
C++中的可调用对象分为以下几种: 函数 函数指针 lambda表达式 bind创建的对象 重载了函数调用运算符(即“()”)的类 函数.函数指针不再介绍.lambda表达式与bind创建的类参考—— ...
- Ubuntu 16.04 使用docker资料汇总与应用docker安装caffe并使用Classifier(ros kinetic+usb_cam+caffe)
Docker是开源的应用容器引擎.若想简单了解一下,可以参考百度百科词条Docker.好像只支持64位系统. Docker官网:https://www.docker.com/ Docker - 从入门 ...
- Python学习笔记:个税起征点上调至5000,算一算少交多少税?
一.旧税率表与新税率表比较 以前起征点是3500,2018年10月1日起起征点正式修改为5000,下面我们用Python来分别计算新旧个人所得税分别为多少? 二.旧的个人所得税 import sys ...