题目传送门

  传送门

题目大意

  餐厅有$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. cesium 飞线 瓣体传感器(雷达扫描) 效果

    参考:github地址 本人新手,npm webpack 这些还是一知半解,只记录自己得到成功结果的操作步骤,可能存在多余或错误的步骤. 1.github 把代码下载下来,解压. 2.webstorm ...

  2. ionic3 添加多个自定义组件

    往往我们创建自定义组件一般都不止只会创建一个自定义组件,创建多个方式如下. 1.创建自定义组件 ionic g component select-car-no ionic g component ae ...

  3. 2018年年度总结 & 2019年计划

      2018关键词 「探索」 引用以前作文最爱写的开头,时间如白驹过隙,回想上次写17年年度总结,仿佛也就过了几日光景.   首先回顾一下17年定下的目标, 18年我将关键字设为探索,目的有两个,一是 ...

  4. 批量将PowerDesigner中表字段由小写变成大写

    通过以下VB脚本即可批量修改,在Tools=>Execute Commands下的Edit/Run Scripts,或者通过Ctrl+Shift+X运行以下脚本即可: '************ ...

  5. selenium常用操作

    1.访问页面获得源码 browser.get(url) browser.page_source 2.查找单个元素:返回一个标签 find_element_by_id  ==>id选择器 find ...

  6. Python 多线程和线程池

    一,前言 进程:是程序,资源集合,进程控制块组成,是最小的资源单位 特点:就对Python而言,可以实现真正的并行效果 缺点:进程切换很容易消耗cpu资源,进程之间的通信相对线程来说比较麻烦 线程:是 ...

  7. 【LeetCode每天一题】Add Binary(二进制加法)

    Given two binary strings, return their sum (also a binary string).The input strings are both non-emp ...

  8. Scala控制语句

    2019-04-16 19:03:01 if else 表达式 var sumVal = 0 if ( sumVal == 0 ) { println("true") } else ...

  9. PHP洗牌、猴子选大王两个小算法

    <一>洗牌算法 /** *洗牌算法washCard *@param $cardNum *@return array */ function washCard($cardNum) { $ca ...

  10. PHP 面向对象之单例模式-有些类也需要计划生育

    一个类只有一个实例对象 1.含义 作为对象的创建模式,单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统全局的提供这个实例.它不会创建实例副本,而是会向单例类内部存储的实例返回一个引用. 2 ...