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$

 

题解:

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$的和的方案数即可。

 

代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 #define N 310
 5 typedef long long LL;
 6 const int mod = 1e9 + 7; 
 7 const double EPS = 1e-12;
 8 
 9 
10 int a[N]; 
11 int f[2][N * N], g[2][N * N];
12 
13 int pow_mod(int x, int p)
14 {
15      int res = 1;
16     for (; p; p >>= 1)
17     {
18         if (p & 1) res = 1LL * res * x % mod;
19         x = 1LL * x * x % mod;
20     }
21     return res;
22 }
23 
24 int main()
25 { 
26     //freopen("in.txt", "r", stdin);
27        
28        int n, s;
29        cin >> n;
30        for (int i = 1; i <= n; ++i)
31            cin >> a[i];
32     cin >> s;
33     
34     int o = 0;
35     f[0][0] = 1;
36     for (int i = 1; i <= n; ++i)
37     {
38         o ^= 1;
39         memcpy(g[o], g[o ^ 1], sizeof(g[o]));
40         memcpy(f[o], f[o ^ 1], sizeof(f[o]));
41         for (int j = s; j >= a[i]; --j)
42         {
43             f[o][j] += g[o ^ 1][j - a[i]];
44             if (f[o][j] >= mod) f[o][j] -= mod;
45             
46             g[o][j] += f[o ^ 1][j - a[i]];
47             if (g[o][j] >= mod) g[o][j] -= mod;
48         }
49     }
50 
51     int ans = 0;
52     for (int i = 0; i <= s; ++i)
53     {
54         ans += 1LL * pow_mod(s - i, n) * f[o][i] % mod;
55         ans -= 1LL * pow_mod(s - i, n) * g[o][i] % mod;
56         if (ans >= mod) ans -= mod;
57         if (ans < 0) ans += mod;
58     }
59     printf("%d\n", ans);
60     return 0;
61 }

 

转载于:https://www.cnblogs.com/vb4896/p/9498549.html

以下是<Arduino.h>头文件的代码示例: ```c++ #ifndef Arduino_h #define Arduino_h #include <stdlib.h> #include <stdbool.h> #include <string.h> #include <math.h> #include <stdint.h> #include <stdio.h> #include <stdarg.h> #include "binary.h" #include "itoa.h" #include "pins_arduino.h" #include "wiring.h" #include "wiring_analog.h" #include "wiring_digital.h" #include "wiring_pulse.h" #include "wiring_shift.h" #include "WInterrupts.h" #ifdef __cplusplus extern "C"{ #endif void setup(void); void loop(void); #ifdef __cplusplus } // extern "C" #endif #endif ``` 以下是<inttypes.h>头文件的代码示例: ```c++ #ifndef _INTTYPES_H_ #define _INTTYPES_H_ #include <stdint.h> #define PRId8 "d" #define PRId16 "d" #define PRId32 "ld" #define PRId64 "lld" #define PRIi8 "i" #define PRIi16 "i" #define PRIi32 "li" #define PRIi64 "lli" #define PRIo8 "o" #define PRIo16 "o" #define PRIo32 "lo" #define PRIo64 "llo" #define PRIu8 "u" #define PRIu16 "u" #define PRIu32 "lu" #define PRIu64 "llu" #define PRIx8 "x" #define PRIx16 "x" #define PRIx32 "lx" #define PRIx64 "llx" #define PRIX8 "X" #define PRIX16 "X" #define PRIX32 "lX" #define PRIX64 "llX" #define PRIdPTR "ld" #define PRIiPTR "li" #define PRIoPTR "lo" #define PRIuPTR "lu" #define PRIxPTR "lx" #define PRIXPTR "lX" #define SCNd8 "hhd" #define SCNd16 "hd" #define SCNd32 "ld" #define SCNd64 "lld" #define SCNi8 "hhi" #define SCNi16 "hi" #define SCNi32 "li" #define SCNi64 "lli" #define SCNo8 "hho" #define SCNo16 "ho" #define SCNo32 "lo" #define SCNo64 "llo" #define SCNu8 "hhu" #define SCNu16 "hu" #define SCNu32 "lu" #define SCNu64 "llu" #define SCNx8 "hhx" #define SCNx16 "hx" #define SCNx32 "lx" #define SCNx64 "llx" #define SCNdPTR "ld" #define SCNiPTR "li" #define SCNoPTR "lo" #define SCNuPTR "lu" #define SCNxPTR "lx" #endif ``` 以下是<Stream.h>头文件的代码示例: ```c++ /* Stream.h - library for stream base class Copyright (C) 2006-2009 David A. Mellis Modified 23 November 2010 by Mark Sproul Modified 3 December 2017 by Chuck Todd */ #ifndef Stream_h #define Stream_h #include "Print.h" #define DEC 10 #define HEX 16 #define OCT 8 #define BIN 2 class Stream : public Print { public: virtual int available() = 0; virtual int read() = 0; virtual int peek() = 0; virtual void flush() = 0; }; #endif ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值