HDU4609 FFT 組合計數

2022-05-21 02:11:14 字數 2501 閱讀 8065

傳送門:

找出n根木棍中取出三根木棍可以組成三角形的概率

我們統計每種長度的棍子的個數

我們對於長度就有乙個多項式

\[f=num[0]*i_0+num[1]*i_1+num[2]*i_2.....num[len]*i_len

\]我們考慮兩根棍子可以組成所有長度的方案數

所以我們對num陣列求一次fft

兩根棍子組成長度的上界是\(len_*2\)

可能存在棍子重複組合的情況,這個時候我們需要去重

去掉兩種重複的情況

1.自己和自己組合 即去除a[i]+a[i]的情況

2.a和b組合 b又和a組合的情況 這種時候每個組合/2即可

然後通過組合數計數即可,tips:在過程中可能爆int

#include #include #include #include #include #include #include #include #include using namespace std;

typedef long long ll;

typedef pairpii;

typedef unsigned long long ull;

#define ls rt<<1

#define rs rt<<1|1

#define lson l,mid,rt<<1

#define rson mid+1,r,rt<<1|1

#define bug printf("*********\n")

#define fin freopen("input.txt","r",stdin);

#define fon freopen("output.txt","w+",stdout);

#define io ios::sync_with_stdio(false),cin.tie(0)

#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"

#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"

#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<>= 1;

} return ans;

}struct complex

} x[maxn];

int a[maxn];

complex operator + (complex a, complex b)

complex operator - (complex a, complex b)

complex operator * (complex a, complex b)

int n, m;

int l, r[maxn];

int limit = 1;

void fft(complex *a, int type)

for(int mid = 1; mid < limit; mid <<= 1) }}

}ll num[maxn];//100000*100000會超int

ll sum[maxn];

int main()

sort(a, a + n);

int len1 = a[n - 1] + 1;

limit = 1;

l = 0;

while(limit < 2 * len1) limit <<= 1, l++;

for(int i = 0; i < len1; i++)

for(int i = len1; i < limit ; i++)

for(int i = 0; i < limit; i++)

fft(x, 1);

for(int i = 0; i < limit; i++)

fft(x, -1);

for(int i = 0; i < limit; i++)

for(int i = 0; i < limit; i++)

limit = 2 * a[n - 1];

//去重,去除 a_i,a_i這種情況

for(int i = 0; i < n; i++)

//去重,去除 (a_i,a_j),(a_j,a_i)這種情況

for(int i = 1; i <= limit; i++)

sum[0] = 0;

for(int i = 1; i <= limit; i++)

sum[i] = sum[i - 1] + num[i];

ll cnt = 0;

for(int i = 0; i < n; i++)

//總數

long long tot = (long long)n * (n - 1) * (n - 2) / 6;

printf("%.7f\n", (double)cnt / tot);

}return 0;

}

HDU4609 FFT 組合計數

傳送門 找出n根木棍中取出三根木棍可以組成三角形的概率 我們統計每種長度的棍子的個數 我們對於長度就有乙個多項式 f num 0 i 0 num 1 i 1 num 2 i 2.num len i len 我們考慮兩根棍子可以組成所有長度的方案數 所以我們對num陣列求一次fft 兩根棍子組成長度的...

組合計數(初步)

組合數學主要是研究某組離散物件滿足一定條件的安排的存在性 構造及計數等問題。組合計數理論是組合數學中乙個最基本的研究方向,主要研究滿足一定條件的安排方式的數目及其計數問題。本課程主要介紹組合數學中常見的和重要的一些計數原理 計數方法和計數公式,包括一般的排列 組合的計算以及生成函式 容斥原理 反演原...

組合計數小啟發

在dp的領域中還有的很大一部分就是組合計數。以前做了fhq在集訓隊作業中的 連邊 這道題,大概就是要你給乙個圖連邊是的若干個點度數為奇數。比較容易發現是一道dp題,但是怎樣保證狀態不重不漏?常用的方法就是增維,比如按照排序大小擴充套件啦,按照字典序擴充套件啦從而使得狀態不重,但是還有兩種方法可以使得...