当前位置: 首页 > news >正文

Equal Sums

很牛阿。

\(n = 20\) 纯唐。

\(n = 500\),我们每次选 \(6\) 个元素有 \(\binom{500}{6} = 2 \times 10^{13}\) 种方案,子集的和的最大值不超过 \(6 \times 10^{12}\),根据鸽巢原理,显然有解。

怎么构造方案呢?我们考虑直接随机就过了。为什么?首先假设子集和是在 \([6, 6 \times 10^{12}]\) 中均匀分布的,则每个数的期望出现次数是 \(\frac{2 \times 10^{13}}{6 \times 10^{12}}=\frac{10}{3}\),那么你选出 \(x\) 个子集和不重复的方案数就是 \(\binom{6 \times 10^{12}}{x} \times (\frac{10}{3})^x\),总方案数是 \(\binom{2 \times 10^{13}}{x}\) 的,显然 \(x\) 很大的时候两者比值趋向 \(0\),即能找到 \(x\) 个不重复的子集和的概率趋向 \(0\),即 \(x\) 次随机后还不能找到解的概率几乎为 \(0\)\(x\)\(2 \times 10^7\) 就基本上一定有解了,至于时间,你放心,\(12\) 秒呢。

考虑不随机的时候,下证随机情况下期望枚举 \(x\) 的次数一定比不随机的大:假设这些子集和构成的集合为 \(T\),每个数出现的次数为 \(c_i\),则不重复的方案数为 \(\binom{|T|}{x} \times \prod_{i \in T} c_i\)\(|T|\) 固定时由均值不等式,\(y_i\) 全相等时最大。如果将 \(|T|\) 变大,方案数也会变多。于是 \(|T|\) 最大,\(c_i\) 都相等时方案数最多,即均匀随机情况下期望枚举 \(x\) 的次数最大。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// typedef __int128 i128;
typedef pair<int, int> pii;
const int N = 2e5 + 10, mod = 998244353;
template<typename T>
void dbg(const T &t) { cout << t << endl; }
template<typename Type, typename... Types>
void dbg(const Type& arg, const Types&... args) {cout << arg << ' ';dbg(args...);
}
namespace Loop1st {
int n;
ll a[N], sum[N];
map<ll, array<ll, 2>>mp;
map<ll, array<ll, 7>>buc;
void main(int tc) {cout << "Case #" << tc << ": "; buc.clear();mp.clear();cin >> n;for (int i = 0; i < n; i++) cin >> a[i];if (n == 20) {for (int s = 1; s < (1 << n); s++) {sum[s] = 0;for (int i = 0; i < n; i++) if (s >> i & 1) sum[s] += a[i];if (mp[sum[s]][0]) {cout << "Possible\n";int t = mp[sum[s]][1];for (int i = 0; i < n; i++) if (t >> i & 1) cout << a[i] << ' ';cout << '\n';for (int i = 0; i < n; i++) if (s >> i & 1) cout << a[i] << ' ';cout << '\n'; return ;}mp[sum[s]] = {1, s};}cout << "Impossible\n";} else {while (true) {int c1 = rand() % (n - 5);int c2 = rand() % (n - 5 - c1) + c1 + 1;int c3 = rand() % (n - 4 - c2) + c2 + 1;int c4 = rand() % (n - 3 - c3) + c3 + 1;int c5 = rand() % (n - 2 - c4) + c4 + 1;int c6 = rand() % (n - 1 - c5) + c5 + 1;// dbg("###", c1, c2, c3, c4, c5, c6);ll s = a[c1] + a[c2] + a[c3] + a[c4] + a[c5] + a[c6];array<ll, 7> cur = {1ll, a[c1], a[c2], a[c3], a[c4], a[c5], a[c6]};if (buc[s][0] && buc[s] != cur) {cout << "Possible\n";array<ll, 7> tmp = buc[s];cout << tmp[1] << ' ' << tmp[2] << ' ' << tmp[3] << ' ' << tmp[4] << ' ' << tmp[5] << ' ' << tmp[6] << '\n';cout << a[c1] << ' ' << a[c2] << ' ' << a[c3] << ' ' << a[c4] << ' ' << a[c5] << ' ' << a[c6] << '\n';return ;}buc[s] = cur;}}
}}
int main() {// freopen("data.in", "r", stdin);// freopen("data.out", "w", stdout);ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);srand(time(0));int T = 1;cin >> T;for (int tc = 1; tc <= T; tc++) Loop1st::main(tc);return 0;
}
http://www.rkmt.cn/news/182811.html

相关文章:

  • 基于NodeJs爱宠之家设计与实现-核心功能模块设计
  • ProfiNet转DeviceNet协议转换网关助力多泵协同,年省电费3万元
  • 读后感
  • GitHub Pull Request审查:Miniconda-Python3.10确保代码可运行
  • EasyAdmin Device Setup 工具完整学习笔记
  • 五指买卖 通达信买卖指标 源码
  • 麒麟系统配置php环境
  • 回文构造
  • Docker容器资源限制:Miniconda-Python3.10绑定GPU与内存配额
  • Conda环境克隆技巧:Miniconda-Python3.10快速复制已有配置
  • SSH远程连接配置指南:通过Miniconda-Python3.10管理多台GPU服务器
  • 2025年终总结之入门SAP EWM
  • HTML模板引擎集成:Miniconda-Python3.10使用Jinja2生成网页
  • GST Tag标签技术系统解析:重组蛋白亲和纯化与检测应用全指南
  • 爆火全网的“瀑布流”视频,手把手教你一键生成,低成本打造爆款!
  • DDR ZQCL与ZQCS
  • Jupyter Notebook密码设置:保护Miniconda-Python3.10远程访问安全
  • Markdown表格美化技巧:在Miniconda-Python3.10中导出Pandas数据
  • GitHub Wiki文档维护:Miniconda-Python3.10生成自动化API文档
  • Python安装日志分析:Miniconda-Python3.10记录详细依赖安装过程
  • 三自由度仿真
  • HTML表单提交处理:Miniconda-Python3.10运行FastAPI后端服务
  • 通达信控盘公式
  • 任务规划与执行:AI Agent的行动决策机制
  • 第一次买云服务器,我踩过的坑希望你能避开
  • Conda list查看已安装包:检查Miniconda-Python3.10中的PyTorch状态
  • Jupyter Lab使用指南:在Miniconda-Python3.10中运行PyTorch代码示例
  • Pyenv which python定位准确解释器:避免Miniconda环境混淆
  • 清华镜像URL列表:Miniconda-Python3.10 pip与conda双源配置
  • Conda初始化报错解决方案:Miniconda-Python3.10预配置环境免踩坑