hihoCoder 1596 : Beautiful Sequence
Description
Consider a positive integer sequence a[1], ..., a[n] (n ≥ 3). If for every 2 ≤ i ≤ n-1, a[i-1] + a[i+1] ≥ 2 × a[i] holds, then we say this sequence is beautiful.
Now you have a positive integer sequence b[1], ..., b[n]. Please calculate the probability P that the resulting sequence is beautiful after uniformly random shuffling sequence b.
You're only required to output (P × (n!)) mod 1000000007. (Obviously P × (n!) is an integer)
Input
First line contains an integer n. (3 ≤ n ≤ 60)
Following n lines contain integers b[1], b[2], ..., b[n]. (1 ≤ b[i] ≤ 1000000000)
Output
Output (P × (n!)) mod 1000000007.
Sample Input
4
1
2
1
3
Sample Output
8
https://hihocoder.com/problemset/problem/1596dp鬼题
题目条件可化为a[i+1]-a[i]>=a[i]-a[i-1]
考虑排序再做分配
根据分析我们发现最后的高度序列是一个勾函数,先减小后增大
我们讨论b[i-1],b[i],b[i+1]的情况
显然i-1和i+1不可能同时大于i
只可能一个大于i一个小于,或两个都大于
但是两个都大于的情况显然只有一次,两边是不会有的
如5 3 5 1 3 5
那么就出现了两个都小于的情况
那么我们就可以dp
令f[i][j][k][l]表示最左边两个为i,j 最右边两个为k,l
我们先将最小值放入f[1][0][1][0]=1
接下来要放的数为max(i,k)+1,为什么?因为是排过序的,从小到大放就行了
判断是否满足:a[i+1]-a[i]>=a[i]-a[i-1]
还有一个细节:
当有多个最小值时,显然不能直接dp,以最小值数量为l=3举例
因为直接dp只能得到4种,而实际有6种(此题鬼处)
所以把所有最小值缩为一个,最后乘l!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int Mod=;
long long f[][][][],a[],p[],tmp,ans;
int n;
int main()
{int i,j,k,l=;
cin>>n;
for (i=;i<=n;i++)
{
scanf("%lld",&a[i]);
}
sort(a+,a+n+);
p[]=;
for (i=;i<=n;i++)
p[i]=(p[i-]*i)%Mod;
for (i=;i<=n;i++)
if (a[i]==a[]) l++;
tmp=p[l];
for (i=;i<=n-l+;i++)
a[i]=a[i+l-];
n=n-l+;
f[][][][]=;
for (i=;i<=n;i++)
{
for (j=;j<=n-;j++)
{
for (k=;k<=n;k++)
{
for (l=;l<=n-;l++)
{
int z=max(i,k)+;
if (z==n+)
{
ans+=f[i][j][k][l];
ans%=Mod;
continue;
}
if (a[z]-a[k]>=a[k]-a[l]||l==)
f[i][j][z][k]+=f[i][j][k][l],f[i][j][z][k]%=Mod;
if (a[z]-a[i]>=a[i]-a[j]||j==)
f[z][i][k][l]+=f[i][j][k][l],f[z][i][k][l]%=Mod;
}
}
}
}
cout<<(ans*tmp)%Mod;
}
hihoCoder 1596 : 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 1061.Beautiful String
题目链接:http://hihocoder.com/problemset/problem/1061 题目意思:给出一个不超过10MB长度的字符串,判断是否里面含有一个beautiful strings ...
- [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\ ...
- hihoCoder挑战赛31
#1595 : Numbers 时间限制:8000ms 单点时限:1000ms 内存限制:256MB 描述 给定n个整数常数c[1], c[2], ..., c[n]和一个整数k.现在需要给2k个整数 ...
- 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 ...
随机推荐
- Vim配置及使用技巧
要说Linux下比较好用的文本编辑器,我推荐vim(当然很多人都用emacs,可我没用过),用vim也有一年左右,有些心得体会想与诸位分享.在我的学习过程中,借鉴了不少优秀的博客,其中有csdn大神n ...
- Beta集合
Beta冲刺day1 Beta冲刺day2 Beta冲刺day3 Beta冲刺day4 Beta冲刺day5 Beta冲刺day6 Beta冲刺day7 测试总结 总结合集 Beta预备
- iOS开发-OC中TabView的编辑
UITableView编辑 1> UITableView 编辑流程 2> UITableView 编辑步骤(四步) ① 第一步 : 让 TableView 处于编辑状态(在按钮点击事件方法 ...
- Flask 学习 四 数据库
class Role(db.Model): __tablename__='roles' id = db.Column(db.Integer,primary_key=True) name = db.Co ...
- 关于mule中Spring使用中的一个问题
在mule中连接数据库时,大家通常喜欢使用spring的数据库连接以及bean的配置,但是在使用时会出现一些问题,即bean无法找到,这些,就是需要把bean的id属性改成name属性:可能是因为mu ...
- 利用java反射读写csv中的数据
前一段有个需求需要将从数据库读取到的信息保存到csv文件中,在实现该需求的时候发现资料比较少,经过收集反射和csv相关资料,最终得到了如下程序. 1.在使用java反射读取csv文件数据时,先通 ...
- 从PRISM开始学WPF(八)導航Navigation?
0x6Navigation Basic Navigation Prism中的Navigation提供了一种类似导航的功能,他可以根据用户的输入,来刷新UI. 先看一个最简单的例子,通过按钮来导航到一个 ...
- Mysql数据库mys和ora库的备份与恢复脚本
!/bin/bash Time=$(date +%Y%md%H%M%S) Back_dir="$HOME/mysqlback/${Time}" function Detect_u_ ...
- jhipster生成项目无法使用restful请求,报access_denied 403错误
写在前边: 我们的微服务是注册中心.uaa.gateway为基础,添加微服务应用,昨天下午在测试jhipster的增删改查,因为jhipster生成的代码都是restful的,好不容易找到网关配置的映 ...
- JavaScript正则表达式学习笔记(二) - 打怪升级
本文接上篇,基础部分相对薄弱的同学请移步<JavaScript正则表达式学习笔记(一) - 理论基础>.上文介绍了8种JavaScript正则表达式的属性,本文还会追加介绍几种JavaSc ...