@description@

给定一个大小为 \(l_1\times l_2 \dots l_d\) 的 d 维超矩形,将它的一个角放置在原点,使得它的第 i 维在范围 \([0, l_i]\)。

求出这个矩形中满足 \(x_1 + x_2 + \dots + x_d \leq s\) 的点形成的体积 × d!。

原题传送门。

@solution@

首先,简单积分一下可以得到满足 \(\sum_{i=1}^{d}x_i \leq s\) 的点形成的体积为 \(\frac{s^d}{d!}\)。

因为数据都是整数,我们不妨去考虑每一个 \(1\times 1 \dots \times 1\) 的单位超矩形 \((x_1, x_2, \dots x_d) - (x_1 + 1, x_2 + 1, \dots x_d + 1)\) 的贡献。

除去完全包含(\(s - \sum_{i=1}^{d}x_i \geq d\))与完全不包含(\(s - \sum_{i=1}^{d}x_i \leq 0\)),还有 d - 1 种不完全包含的情况 (\(0 < s - \sum_{i=1}^{d}x_i < d\))。

可以作个背包 + 简单前缀和优化算出每一种情况有多少个单位超矩形。

然而不完全包含的情况并不能直接通过积分算体积。不妨仍考虑组合方法,记 \(f_j\) 表示满足 \(s - \sum_{i=1}^{d}x_i = j\) 的体积。

对于 \(\sum_{i=1}^{d}x_i \leq s\),积分出来的体积是 \(\frac{s^d}{d!}\);然而我们也可以采用单位超矩形的贡献算出体积。

不妨只考虑 s < d 的情况,则可以列出等式 \(\frac{s^d}{d!} = \sum_{i=0}^{s}{s - i + d - 1\choose d - 1}f_i\),由此就可以在 \(f_s\) 与 \(f_{0...s-1}\) 之间建立递推关系。

时间复杂度瓶颈在背包的部分,为 O(l^3)。

@accepted code@

#include <cstdio>
#include <algorithm>
using namespace std; const int MAXN = 300;
const int MAXS = MAXN*MAXN;
const int MOD = int(1E9) + 7; inline int add(int x, int y) {return (x + y) % MOD;}
inline int mul(int x, int y) {return 1LL*x*y % MOD;}
inline int sub(int x, int y) {return add(x, MOD-y);} int pow_mod(int b, int p) {
int ret = 1;
for(int i=p;i;i>>=1,b=mul(b,b))
if( i & 1 ) ret = mul(ret, b);
return ret;
} int l[MAXN + 5], d, s, S; int fct[2*MAXN + 5], ifct[2*MAXN + 5];
int comb(int n, int m) {
return mul(fct[n], mul(ifct[m], ifct[n-m]));
}
int f[MAXN + 5];
void init() {
fct[0] = 1;
for(int i=1;i<=2*d;i++)
fct[i] = mul(fct[i-1], i);
ifct[2*d] = pow_mod(fct[2*d], MOD-2);
for(int i=2*d-1;i>=0;i--)
ifct[i] = mul(ifct[i+1], i+1);
for(int i=1;i<=d;i++) {
// f[i] = mul(pow_mod(i, d), ifct[d]);
f[i] = pow_mod(i, d);
for(int j=0;j<i;j++)
f[i] = sub(f[i], mul(comb(i-j+d-1, d-1), f[j]));
}
} int g[MAXS + 5];
int main() {
scanf("%d", &d), init();
for(int i=1;i<=d;i++)
scanf("%d", &l[i]), l[i]--;
scanf("%d", &s);
g[0] = 1;
for(int i=1;i<=d;i++) {
S += l[i];
for(int j=1;j<=S;j++) g[j] = add(g[j], g[j-1]);
for(int j=S;j>l[i];j--) g[j] = sub(g[j], g[j-l[i]-1]);
}
int ans = 0;
for(int i=0;i<=s;i++)
ans = add(ans, mul(f[min(s-i,d)], g[i]));
printf("%d\n", ans);
}

@details@

一开始总以为它是一道积分题,结果发现怎么积分都不对劲。

然后尝试不从积分走而从组合数学走,发现还真能做出来。

@gym - 100958J@ Hyperrectangle的更多相关文章

  1. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  2. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  3. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  4. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  5. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  6. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  7. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

  8. Gym 101102D---Rectangles(单调栈)

    题目链接 http://codeforces.com/gym/101102/problem/D problem  description Given an R×C grid with each cel ...

  9. Gym 101102C---Bored Judge(区间最大值)

    题目链接 http://codeforces.com/gym/101102/problem/C problem description Judge Bahosain was bored at ACM ...

随机推荐

  1. Java集合--阻塞队列及各种实现的解析

    阻塞队列(Blocking Queue) 一.队列的定义 说的阻塞队列,就先了解下什么是队列,队列也是一种特殊的线性表结构,在线性表的基础上加了一条限制:那就是一端入队列,一端出队列,且需要遵循FIF ...

  2. Spring 基于注解的配置 简介

    基于注解的配置 从 Spring 2.5 开始就可以使用注解来配置依赖注入.而不是采用 XML 来描述一个 bean 连线,你可以使用相关类,方法或字段声明的注解,将 bean 配置移动到组件类本身. ...

  3. SICP 题解集合

    1.1(略) 1.2 biwascheme> (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5))))) (* 3 (- 6 2) (- 2 7))) => -0.24666 ...

  4. hdu2093 考试排名(还需完善)

    下面代码是借鉴的.好多的知识点等着完善 #include <iostream> #include <string> #include <algorithm> usi ...

  5. [工具推荐]003.Tortoisegit使用教程

    Git简介:       Git是一款免费.开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目,是一个开源的分布式版本控制系统,用以有效.高速的处理从很小到非常大的项目版本管理.Git 是 ...

  6. Linux 比较常用的命令

    #磁盘空间 df -h 显示已经挂载的分区列表 du -sh [file] 估算当前使用磁盘空间 du -sk * | sort -rn 以容量大小递减排序 文件搜索 find find [file_ ...

  7. 多用户vps管理面板怎么安装,有没有好用的vps管理工具

    一.VPS安装VPSMate控制面板步骤 1.使用SSH连接到VPS.使用命令获取VPSMate安装包: wget   http://www.vpsmate.org/tools/install.py ...

  8. PowerPC-Link Command File解析

    https://mp.weixin.qq.com/s/CATWma2mv5IPYGtKZLuGDA   以Code Warrior 11生成的flash版本(FLASH.lcf)为例   一. 参考资 ...

  9. Chisel3 - bind - Data

    https://mp.weixin.qq.com/s/ENJVkz88sGgyODRNCu9jhQ   介绍Data类中的binding的定义和用法.   Binding stores informa ...

  10. css引入方式和基本样式

    css的三种引入方式: 1.内嵌:直接在标签中添加style属性 格式:<标签名 style="样式1:样式值1:样式2=样式值2:"></标签名> 2.内 ...