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: ...
随机推荐
- 关于Object.defineProperty的get和set
面试经常提问vue双向数据绑定的原理,其主要是依赖于Object.definePropety(); Object.definePropety下面有get和set方法. get指读取属性时调用的放法,s ...
- Coursera-Algotithms学习
Week1 Job Interview Question Social network connectivity. Given a social network containing N member ...
- Android studio及eclipse中的junit单元測试
转载请标明出处:http://blog.csdn.net/nmyangmo/article/details/51179106 前一段时间有人问我单元測试的相关内容,我稍作总结做日志例如以下: 由于我接 ...
- php使用curl请求数据(采集数据)
<?php $url = "http://www.baidu.com/s?wd=刘俊涛的博客"; $header = array( 'User-Agent: Mozilla/ ...
- JDBC:数据库操作:处理大对象CLOB数据
目标: 了解大对象处理基本原理, 掌握CLOB数据的读,写操作. 可以使用CLOB类处理大文本数据. 大对象处理主要指CLOB和BLOB两种类型字段.可以大量存储文字. 要想在程序中处理这样的大数据操 ...
- (四)Lucene——搜索和相关度排序
1. 搜索 1.1 创建查询对象的方式 通过Query子类来创建查询对象 Query子类常用的有:TermQuery.NumericRangeQuery.BooleanQuery 特点:不能输入luc ...
- hibernate的配置, 增删改查
路径:查找路径 实际上都是查找编译后的对应的路径,在bin文件夹中总 增删改必须开启事务才行 hibernate加载文件的两种方式 configure 1.引包 antlr-2.7.6.jar bac ...
- ASP.Net 自定义HttpModule注册管道事件
背景: 一个请求在到达处理器时 可能需要做很多重复的工作 比如使用固定的算法推算出用户id 角色 如果在应用程序各处做重复解析 会产生大量代码冗余 还有能想到的诸如记录访问者 应用日志 统计流量 ...
- ASP.NET绑定CHECKBOXLIST--------JQUERY绑定CLICK事件,获取CHECKBOX的VALUE和显示值
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs ...
- NYOJ 10 skiing (深搜和动归)
skiing 时间限制:3000 ms | 内存限制:65535 KB 难度:5 描写叙述 Michael喜欢滑雪百这并不奇怪. 由于滑雪的确非常刺激.但是为了获得速度.滑的区域必须向下倾斜.并且 ...