合并石子--Garsia-Wachs贪心
题意: 有n堆石子,每次可以合并相邻两个石子,代价为两堆石子的和,求将这堆石子合并为一堆的最小代价。 这道题可以用平衡树做,只是维护的东西很多很多,会非常难受 所以我就退而求其次,选择了ZJC大爷的卡常做法 1e5的数据范围也能在1s内轻松卡过啦!!! 思路与 Garsia-Wachs算法一致 代码如下 #include<bits/stdc++.h> using namespace std; unsigned int tot; unsigned long long a[500005]; int n; int read() { char c; int x; for(c=getchar();c!='-'&&(c>'9'||c<'0');c=getchar()); if(c=='-') { x=0; for(c=getchar();c>='0'&&c<='9';c=getchar()) x=x*10+c-'0'; return -x; } else { x=c-'0'; for(c=getchar();c>='0'&&c<='9';c=getchar()) x=x*10+c-'0'; return x; } } unsigned long long ans; void unionn(const unsigned int x) { unsigned int i,j,d; unsigned