题目传送门

  传送门

题目大意

  餐厅有$n$张桌子,第$i$张桌子可以容纳$c_i$个人,有$t$组客人,每组客人的人数等概率是$[1, g]$中的整数。

  每来一组人数为$x$客人,餐厅如果能找到最小的$c_j$使得$c_j \geqslant x$,那么就会把这张桌子分配给这些客人,并得到$x$的收益。

  问期望的收益。

  好像可以枚举每一种人数,然后算一下,但时间复杂度很爆炸。

  先添加若干个容量为$\infty$的桌子。这样每组人一定能够分配到一张桌子,只是可能没有收益。

  考虑最后答案一定是将桌子排序后,若干段连续的桌子被占用。

  用$f_{l, r}$表示恰好$[l, r]$这段桌子被占用的所有方案的收益总和和方案数。每次转移考虑枚举最后一组人来的时候占用的桌子,假如它是$mid$,那么最后一组人可行的人数是$(c_{l - 1}, c_{mid}]$。

  然后做一个背包,$h_{i, j}$表示考虑到在时刻$i$及其之后来的人,被占用的最靠左的左端点是$j$,所有方案的收益总和和方案数。转移的时候枚举这一段的长度,以及前一段的区间的左端点,注意两个区间不能相交。后者用一个后缀和优化掉。

  注意每组人是带标号的,所以合并两个方案的时候还需要分配标号。

Code

 /**
* Codeforces
* Gym#101623E
* Accepted
* Time: 46ms
* Memory: 2600k
*/
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
using namespace std;
typedef bool boolean; typedef long double ld;
typedef pair<ld, ld> pdd; pdd operator + (const pdd& a, const pdd& b) {
return pdd(a.first + b.first, a.second + b.second);
} pdd operator * (const pdd& a, const pdd& b) {
return pdd(a.first * b.second + a.second * b.first, a.second * b.second);
} pdd operator * (const pdd& a, ld x) {
return pdd(a.first * x, a.second * x);
} ld nature_sum(int x) {
return x * (x + ) >> ;
} const int N = ; int n, g, t;
vector<int> c;
ld C[N << ][N << ];
pdd f[N << ][N << ], h[N][N << ], s[N][N << ]; inline void init() {
scanf("%d%d%d", &n, &g, &t);
c.resize(n);
for (int i = ; i < n; i++) {
scanf("%d", &c[i]);
c[i] = min(c[i], g);
}
for (int i = ; i < t; i++)
c.push_back(g + );
sort(c.begin(), c.end());
n = c.size();
} inline void solve() {
C[][] = ;
for (int i = ; i <= n; i++) {
C[i][] = C[i][i] = ;
for (int j = ; j < i; j++)
C[i][j] = C[i - ][j] + C[i - ][j - ];
} for (int r = ; r < n; r++)
for (int l = r; ~l; l--) {
for (int mid = l; mid <= r; mid++) {
pdd val; //(0, 1);//C[r - l][r - mid]);
if (c[mid] > g)
val = pdd(, g - ((l) ? (min(c[l - ], g)) : ()));
else
val = pdd(nature_sum(c[mid]) - ((l) ? (nature_sum(c[l - ])) : ()), c[mid] - ((l) ? (c[l - ]) : ()));
pdd vall = (mid > l) ? (f[l][mid - ] * C[r - l][r - mid]) : (pdd(, ));
pdd valr = (mid < r) ? (f[mid + ][r]) : (pdd(, ));
f[l][r] = f[l][r] + (vall * val * valr);
}
// cerr << l << " " << r << " " << f[l][r].first << " " << f[l][r].second << '\n';
} for (int i = ; i < t; i++)
for (int j = ; j < n - t + i + ; j++)
h[i][j] = f[j][j + t - i - ];
for (int i = t; i--; ) {
int all = t - i;
for (int j = ; j + all < n; j++) {
for (int k = i + ; k < t; k++) {
int put = k - i;
// cerr << i << " " << j << " " << k << " " << all << " " << put << '\n';
ld comb = C[all][put];
h[i][j] = h[i][j] + (f[j][j + put - ] * comb * s[k][j + put + ]);
}
// cerr << i << " " << j << " " << h[i][j].first << " " << h[i][j].second << '\n';
}
s[i][n - ] = h[i][n - ];
for (int j = n - ; j >= ; j--)
s[i][j] = s[i][j + ] + h[i][j];
}
pdd ans(, );
for (int i = ; i < n; i++)
ans = ans + h[][i];
// cout << (ans.first / ans.second) << '\n';
double E = ans.first / ans.second;
printf("%.9lf", E);
} int main() {
init();
solve();
return ;
}

Codeforces 101623E English Restaurant - 动态规划的更多相关文章

  1. Codeforces 839C Journey - 树形动态规划 - 数学期望

    There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can r ...

  2. Codeforces 834D The Bakery - 动态规划 - 线段树

    Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredient ...

  3. Codeforces 837D Round Subset - 动态规划 - 数论

    Let's call the roundness of the number the number of zeros to which it ends. You have an array of n ...

  4. CodeForces 623E Transforming Sequence 动态规划 倍增 多项式 FFT 组合数学

    原文链接http://www.cnblogs.com/zhouzhendong/p/8848990.html 题目传送门 - CodeForces 623E 题意 给定$n,k$. 让你构造序列$a( ...

  5. Codeforces 264C Choosing Balls 动态规划

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF264C.html 题目传送门 - CF264C 题意 给定一个有 $n$ 个元素的序列,序列的每一个元素是个 ...

  6. Codeforces 1000G Two-Paths 树形动态规划 LCA

    原文链接https://www.cnblogs.com/zhouzhendong/p/9246484.html 题目传送门 - Codeforces 1000G Two-Paths 题意 给定一棵有 ...

  7. codeforces 17C Balance(动态规划)

    codeforces 17C Balance 题意 给定一个串,字符集{'a', 'b', 'c'},操作是:选定相邻的两个字符,把其中一个变成另一个.可以做0次或者多次,问最后可以生成多少种,使得任 ...

  8. Codeforces 762D Maximum path 动态规划

    Codeforces 762D 题目大意: 给定一个\(3*n(n \leq 10^5)\)的矩形,从左上角出发到右下角,规定每个格子只能经过一遍.经过一个格子会获得格子中的权值.每个格子的权值\(a ...

  9. CF思维联系–CodeForces - 225C. Barcode(二路动态规划)

    ACM思维题训练集合 Desciption You've got an n × m pixel picture. Each pixel can be white or black. Your task ...

随机推荐

  1. c#重命名文件,报错“System.NotSupportedException”类型的未经处理的异常在 mscorlib.dll 中发生”

    修改远程服务器的文件名,报错“System.NotSupportedException”类型的未经处理的异常在 mscorlib.dll 中发生”,“System.NotSupportedExcept ...

  2. 在多个平台如何安装Python

    最近的一个项目,架构师米洛需要用的mqtt,服务器开发的时候,竟然用的python脚本.运行python就需要安装开发环境,好吧,百度一下就知道了大神廖雪峰.以下部分测试通过,转载记录如下. 因为Py ...

  3. 《ABCD组团队》第二次作业

    ABCD组:二手车价格预测系统 项目 内容 这个作业属于哪个课程 http://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 https://www.cnblogs.c ...

  4. 截取字段split

    172.0.0.1String[] splitAddress=qip.split("\\.");//--172001 String ip=splitAddress[0]+" ...

  5. STM32 内部flash的读写程序

    ​ /* Base address of the Flash sectors */ #define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base ...

  6. abap test seam 和 TEST-INJECTION

    TEST-SEAM 和 TEST-INJECTION 一块儿使用 可以模拟出调用方法的return,exporting,chaning值.  例如: 1: 假设有一个类zcl_demo_input,该 ...

  7. emqx源码编译

    1  下载  github上下载 2  找台虚拟机,安装编译所需的环境,erlang   make等 3  执行make命令 重点说一下第3步: 主要是make命令报错 解释:执行make命令后,依赖 ...

  8. 【Bad Practice】12306 query

  9. oracle之数据恢复(delete误删)

    ALTER TABLE TA_申请材料表 ENABLE row movement ; flashback table TA_申请材料表 to timestamp to_timestamp('2019- ...

  10. 从零开始搭建一个vue.js的脚手架

    在谷歌工作的时候,我们要做很多界面的原型,要求快速上手,灵活运用,当时用的一些现有框架,比如angular,太笨重了——尤雨溪(Vue.js 作者) vue.js是现在一个很火的前端框架,官网描述其简 ...