题目大意:

给出一个$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. Hibernate关系映射(一) 基于外键的单向一对一

    模拟用户和地址的映射关系,一个用户只有一个地址,用户知道地址,但是地址不知道用户.用户对地址的单向一对一映射. 一.建立实体类 Account.cs类 package com.lxit.entity; ...

  2. Android app启动耗时分析

    前言 app启动耗时过长的话,无论你的app里面的内容多么丰富有趣,作为一个用户,首先是没有耐心去等待的,如果我是一个用户,我会这样想:这是什么垃圾公司出的什么烂app,再等2s不进来就卸载,黑人问号 ...

  3. MSSQL数据库迁移到Oracle(二)

    上一篇文章采用的PowerDesigner实现对MSSQL数据库迁移到Oracle,后来博友建议用ESF Database Migration Toolkit进行迁移会更加简单方便,本文就是通过一个实 ...

  4. mysql,给每一条数据的某一个字段生成不同的随机数

    UPDATE t_article ta-- 利用LEFT JOIN的方式进行关联修改 LEFT JOIN(-- 先通过查询的方式给每一条数据生成对应的10-500之间随机数 SELECT articl ...

  5. NET:Checkboxlist,Dropdownlist 加入ToolTip说明

    ToolTip属性: ToolTip 类 (System.Windows.Controls)‎ 表示创建弹出项的控件.该弹出项可显示界面中元素的相关信息.命名空间: System.Windows.Co ...

  6. CSS3文本溢出

    text-overflow: text-overflow:clip | ellipsis; clip:剪切多余的文字. ellipsis:文本溢出时显示省略标记. 要实现文本溢出剪切显示省略标记,还需 ...

  7. 【Python3 爬虫】17_爬取天气信息

    需求说明 到网站http://lishi.tianqi.com/kunming/201802.html可以看到昆明2018年2月份的天气信息,然后将数据存储到数据库. 实现代码 #-*-coding: ...

  8. 【PHP】(原创)之表单FORM的formhash校验,以TP3.2示例

    1.目的:每次表单POST提交(ajax的POST也适用)过来数据,都必须校验formhash参数是否和服务器端的一致,不一致说明重复提交或者 跨站攻击提交csrf 2.原理:参照了 KPPW 的fo ...

  9. C# 取时间段年、月、日、季度

    DateTime dt = DateTime.Now;  //当前时间             DateTime startWeek = dt.AddDays(1 - Convert.ToInt32( ...

  10. VMware配置网络的3种方式:NAT、Host-Only、Bridged

    网络常识: 1.网络中对电脑的访问是通过ip定位的 就好像我们的身份证号,可以唯一辨识一个人.ip是用来区分网络中的电脑的,因此同一网络(准确讲是“网段”)中,ip地址不能相同.如果同一网络中有相同的 ...