日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

#3771. Triple(生成函数 + 容斥)

發布時間:2023/12/4 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 #3771. Triple(生成函数 + 容斥) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#3771. Triple

考慮只有一個損失時,損失值的生成函數為A(x)A(x)A(x)

如果不考慮無序方案,有兩個損失的生成函數為B(x)=A(x)A(x)B(x) =A(x)A(x)B(x)=A(x)A(x),同理有三個的時候C(x)=A(x)A(x)A(x)C(x) = A(x)A(x)A(x)C(x)=A(x)A(x)A(x)。

考慮如何得到無序方案:

選擇兩個的時候:

ababab的排列有ab,baab, baab,ba兩種,我們先減去aa,bbaa, bbaa,bb的然后除以二就是B(x)B(x)B(x)了,所以B(x)=A(x)A(x)?D(x)2B(x) = \frac{A(x)A(x) - D(x)}{2}B(x)=2A(x)A(x)?D(x)?。

選擇三個的時候:

abcabcabc的排列共有666種,同樣的我們先減去aaa,bbb,cccaaa, bbb, cccaaa,bbb,ccc這樣相同的,然后除以666就是C(x)=A(x)A(x)A(x)?E(x)2C(x) = \frac{A(x)A(x)A(x) - E(x)}{2}C(x)=2A(x)A(x)A(x)?E(x)?。

#include <bits/stdc++.h>using namespace std;struct Complex {double r, i;Complex(double _r = 0, double _i = 0) : r(_r), i(_i) {} };Complex operator + (const Complex &a, const Complex &b) {return Complex(a.r + b.r, a.i + b.i); }Complex operator - (const Complex &a, const Complex &b) {return Complex(a.r - b.r, a.i - b.i); }Complex operator * (const Complex &a, const Complex &b) {return Complex(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r); }Complex operator / (const Complex &a, const Complex &b) {return Complex((a.r * b.r + a.i * b.i) / (b.r * b.r + b.i * b.i), (a.i * b.r - a.r * b.i) / (b.r * b.r + b.i * b.i)); }Complex operator * (const Complex &a, const double &b) {return Complex(a.r * b, a.i * b); }typedef long long ll;const int N = 3e5 + 10;int r[N];Complex x[N], y[N], z[N], ans[N];void get_r(int lim) {for (int i = 0; i < lim; i++) {r[i] = (i & 1) * (lim >> 1) + (r[i >> 1] >> 1);} }void FFT(Complex *f, int lim, int rev) {for (int i = 0; i < lim; i++) {if (i < r[i]) {swap(f[i], f[r[i]]);}}const double pi = acos(-1.0);for (int mid = 1; mid < lim; mid <<= 1) {Complex wn = Complex(cos(pi / mid), rev * sin(pi / mid));for (int len = mid << 1, cur = 0; cur < lim; cur += len) {Complex w = Complex(1, 0);for (int k = 0; k < mid; k++, w = w * wn) {Complex x = f[cur + k], y = w * f[cur + mid + k];f[cur + k] = x + y, f[cur + mid + k] = x - y;}}}if (rev == -1) {for (int i = 0; i < lim; i++) {f[i].r /= lim;}} }int main() {// freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout);// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);int n;scanf("%d", &n);for (int i = 1, a; i <= n; i++) {scanf("%d", &a);x[a].r++, y[a + a].r++, z[a + a + a].r++;} int lim = 1;while (lim <= 3 * 40000) {lim <<= 1;}get_r(lim);FFT(x, lim, 1), FFT(y, lim, 1), FFT(z, lim, 1);for (int i = 0; i < lim; i++) {ans[i] = ans[i] + (x[i] * x[i] * x[i] - 3.0 * x[i] * y[i] + 2 * z[i]) * (1.0 / 6.0);ans[i] = ans[i] + (x[i] * x[i] - y[i]) * (1.0 / 2);ans[i] = ans[i] + x[i];}FFT(ans, lim, -1);for (int i = 0; i < lim; i++) {int res = int(ans[i].r + 0.5);if (res) {printf("%d %d\n", i, res);}}return 0; }

總結

以上是生活随笔為你收集整理的#3771. Triple(生成函数 + 容斥)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。