XV Open Cup named after E.V. Pankratiev Stage 6, Grand Prix of Japan Problem J. Hyperrectangle
题目大意:
给出一个$d$维矩形,第i维的范围是$[0, l_i]$. 求满足$x_1 + x_2 + ...x_d \leq s$ 的点构成的单纯形体积。
$d, l_i \leq 300$
题解:
给出了求$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的更多相关文章
- 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: ...
- 【推导】【贪心】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长路径. 直接贪心染色,对一个点染上其相邻的点的颜色集合之中,未出现过的最小的颜色. 如果染成就染成了 ...
- 【枚举】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种,然后保证其为最大块,去算其他块的切法,即让其他块切得尽可能大即可 ...
- 【二分】【字符串哈希】【二分图最大匹配】【最大流】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的循环子串都哈希出来,相当于对每个字符串,找一个与其他字符串所选 ...
- 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[ ...
- 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 ...
- 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 ...
- 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 ...
- 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: ...
随机推荐
- flex 布局示例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 导出oracle 到 mysql的解决办法
导出oracle 到 mysql的解决办法 使用sqluldr2 命令如下sqluldr2 USER=weibh/1234@dydb file=c:\1.txt sql=sql.sql FORMA ...
- python的基本知识点
一.数据类型 1.整数2.浮点数3.字符串4.布尔值:True/False5.空值:None 二.变量 变量名必须是大小写英文.数字和_的组合,且不能以数字开头 三.常量 全部大写的变量名表示常量,p ...
- Android蓝牙音乐获取歌曲信息
由于我在蓝牙开发方面没有多少经验,如果只是获取一下蓝牙设备名称和连接状态那么前面的那篇文章就已经足够了,接下来的内容是转自一个在蓝牙音乐方面颇有经验的开发者的博客,他的这篇文章对我帮助很大. 今天,先 ...
- [XCode A] - 编程相关问题
1.如何在XCode中新建文件夹 如果在xcode工程中new group,只是在视觉效果上分好了几个文件夹,方便分类管理,但在finder中并不会创建新的文件夹,在硬盘目录还是所有文件都并列在一个文 ...
- list_entry(ptr, type, member)——知道结构体内某一成员变量地址,求结构体地址
#define list_entry(ptr, type, member) \ ((type *)(() -> member))) 解释: 1 在0这个地址看做有一个虚拟的type类型的变量,那 ...
- JavaScript经常使用代码段
把例如以下代码增加<body>区域中: 后退 前进 <!--<input type="button" value="后退" onClic ...
- Tomcat_启动参数设置
1.修改启动时内存参数.并指定JVM时区 (在windows server 2008 下时间少了8个小时): 在Tomcat上运行j2ee项目代码时,经常会出现内存溢出的情况,解决办法是在系统参数中增 ...
- Linux REMOTE HOST IDENTIFICATION HAS CHANGED错误解决方法
http://linuxme.blog.51cto.com/1850814/375752 WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED解决 ...
- C#7.0之元组数据
static (string,string,string) LookupName(int a) { return ("","",""); } ...