题目大意:

给出一个$d$维矩形,第i维的范围是$[0, l_i]$. 求满足$x_1 + x_2 + ...x_d \leq s$ 的点构成的单纯形体积。

$d, l_i \leq 300$

题解:

watashi学长的blog传送门

给出了求$a_1x_1 + a_2x_2 + ...a_dx_d \leq b $的通用做法。答案就是一个神奇的式子$\frac{1}{n!} * \sum_{I \subseteq S}{(-1)^{|I|}}*max\{0, b - \sum_{i \in I}{a_il_i}\}^d$

背包一下分别求出取了奇数个和偶数个$l_i$的和的方案数即可。

代码:

 #include <bits/stdc++.h>
using namespace std; #define N 310
typedef long long LL;
const int mod = 1e9 + ;
const double EPS = 1e-; int a[N];
int f[][N * N], g[][N * N]; int pow_mod(int x, int p)
{
int res = ;
for (; p; p >>= )
{
if (p & ) res = 1LL * res * x % mod;
x = 1LL * x * x % mod;
}
return res;
} int main()
{
//freopen("in.txt", "r", stdin); int n, s;
cin >> n;
for (int i = ; i <= n; ++i)
cin >> a[i];
cin >> s; int o = ;
f[][] = ;
for (int i = ; i <= n; ++i)
{
o ^= ;
memcpy(g[o], g[o ^ ], sizeof(g[o]));
memcpy(f[o], f[o ^ ], sizeof(f[o]));
for (int j = s; j >= a[i]; --j)
{
f[o][j] += g[o ^ ][j - a[i]];
if (f[o][j] >= mod) f[o][j] -= mod; g[o][j] += f[o ^ ][j - a[i]];
if (g[o][j] >= mod) g[o][j] -= mod;
}
} int ans = ;
for (int i = ; i <= s; ++i)
{
ans += 1LL * pow_mod(s - i, n) * f[o][i] % mod;
ans -= 1LL * pow_mod(s - i, n) * g[o][i] % mod;
if (ans >= mod) ans -= mod;
if (ans < ) ans += mod;
}
printf("%d\n", ans);
return ;
}

XV Open Cup named after E.V. Pankratiev Stage 6, Grand Prix of Japan Problem J. Hyperrectangle的更多相关文章

  1. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem A. Arithmetic Derivative

    题目:Problem A. Arithmetic DerivativeInput file: standard inputOutput file: standard inputTime limit: ...

  2. 【推导】【贪心】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem H. Path or Coloring

    题意:给你一张简单无向图(但可能不连通),再给你一个K,让你求解任意一个问题:K染色或者输出一条K长路径. 直接贪心染色,对一个点染上其相邻的点的颜色集合之中,未出现过的最小的颜色. 如果染成就染成了 ...

  3. 【枚举】XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016 Problem D. Cutting Potatoes

    题意:有n个土豆,每个有体积V(i),你可以将每个土豆等分为不超过K份,问你最大块和最小块比值最小为多少. 直接枚举切法,只有n*K种,然后保证其为最大块,去算其他块的切法,即让其他块切得尽可能大即可 ...

  4. 【二分】【字符串哈希】【二分图最大匹配】【最大流】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem I. Minimum Prefix

    给你n个字符串,问你最小的长度的前缀,使得每个字符串任意循环滑动之后,这些前缀都两两不同. 二分答案mid之后,将每个字符串长度为mid的循环子串都哈希出来,相当于对每个字符串,找一个与其他字符串所选 ...

  5. Problem A. Array Factory XVII Open Cup named after E.V. Pankratiev Stage 4: Grand Prix of SPb, Sunday, Octorber 9, 2016

    思路: 直接二分长度不可行,因为有负数. 考虑枚举坐便删l个数,那如果可以在短时间内求出符合条件的右边最小删的数的个数,这题便可做了. 即:当左边删l个数时,要使sum[n]-sum[l]-fsum[ ...

  6. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game

    题目: Problem F. Matrix GameInput file: standard inputOutput file: standard inputTime limit: 1 secondM ...

  7. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem J. Terminal

    题目:Problem J. TerminalInput file: standard inputOutput file: standard inputTime limit: 2 secondsMemo ...

  8. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem L. Canonical duel

    题目:Problem L. Canonical duelInput file: standard inputOutput file: standard outputTime limit: 2 seco ...

  9. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem D. Clones and Treasures

    题目:Problem D. Clones and TreasuresInput file: standard inputOutput file: standard outputTime limit: ...

随机推荐

  1. 微博轻量级RPC框架Motan正式开源:支撑千亿调用

    支撑微博千亿调用的轻量级 RPC 框架 Motan 正式开源了,项目地址为https://github.com/weibocom/motan. 微博轻量级RPC框架Motan正式开源 Motan 是微 ...

  2. 算法笔记_079:蓝桥杯练习 区间k大数查询(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 给定一个序列,每次询问序列中第l个数到第r个数中第K大的数是哪个. 输入格式 第一行包含一个数n,表示序列长度. 第二行包含n个正整数,表 ...

  3. java设计模式之策略

    今天你的leader兴致冲冲地找到你,希望你可以帮他一个小忙,他现在急着要去开会.要帮什么忙呢?你很好奇. 他对你说,当前你们项目的数据库中有一张用户信息表,里面存放了很用户的数据,现在需要完成一个选 ...

  4. Oracle中查询某字段不为空或者为空的SQL语句怎么写

    比如 insert into table a (a1,b1)values("a1",''); 对于这种情况,因为表里存的是'',其实是没有内容的,要查询这个字段,不能直接使用 se ...

  5. Android实现截图分享qq,微信

    代码地址如下:http://www.demodashi.com/demo/13292.html 前言 现在很多应用都有截图分享的功能,今天就来讲讲截图分享吧 今天涉及到以下内容: android权限设 ...

  6. Android App补丁更新

    上一周比较忙,忙的不可开交,写的文章也就两篇,在此希望大家见谅.这周呢,突然闲下来了,有时间了,就重构了下代码,捣鼓点前卫的技术,沉淀沉淀.所以呢,今天就分享下这几天研究的东西. 移动互联网主打的就是 ...

  7. java基础讲解06-----字符串

    1. package test; public class chb01 { public static void main(String[] ggs)        {            /**  ...

  8. ASP.Net 自定义HttpModule注册管道事件

    背景: 一个请求在到达处理器时 可能需要做很多重复的工作 比如使用固定的算法推算出用户id 角色   如果在应用程序各处做重复解析 会产生大量代码冗余 还有能想到的诸如记录访问者 应用日志 统计流量 ...

  9. javascript解析器(引擎)

    The JavaScript interpreter in a browser is implemented as a single thread. javascript 引擎在浏览器中作为单线程实现 ...

  10. window下安装Node.js NPM

    一.安装Node.js 下载地址:http://nodejs.org/download/ 1..msi文件,直接安装,包括了npm,结束. 2..exe文件,把node.exe所在主目录,加入到系统P ...