题目大意:给定$n$个数,第$i$个数为$a_i$,记这$n$个数的所有非空子集的和分别为$s_1,s_2,\dots,s_{2^n-1}$;求$s$的中位数。

题解:假设考虑的是所有子集,包括空子集。

令$sum=\sum\limits_{t=1}^n a_i$。

若有一个子集和为$x$,存在另一个子集和为$sum-x$。

因此不含空子集的中位数等价于所有出现过的数的中间两个的后一个。

$0/1$背包就好了,可以用$bitset$优化

卡点:

C++ Code:

#include <cstdio>
#include <bitset>
using namespace std;
int n, s, sum;
bitset<2000001> v;
int main() {
scanf("%d", &n);
v[0] = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &s);
sum += s;
v |= v << s;
}
for (int i = sum + 1 >> 1; i <= sum; i++) {
if (v[i]) {
printf("%d\n", i);
break;
}
}
return 0;
}

  

[AT3857]Median Sum的更多相关文章

  1. AtCoder3857:Median Sum (Bitset优化背包&&对称性求中位数)

    Median Sum You are given N integers A1, A2, ..., AN. Consider the sums of all non-empty subsequences ...

  2. Atcoder 3857 Median Sum

    Problem Statement You are given N integers A1, A2, ..., AN. Consider the sums of all non-empty subse ...

  3. 2018.08.10 atcoder Median Sum(01背包)

    传送门 题意简述:输入一个数组an" role="presentation" style="position: relative;">anan. ...

  4. AGC020C Median Sum

    高端操作qaq 又双叒叕读错题了= = 然后重新读题发现不会做了 于是瞅了一波题解 我靠要不要这么暴力呜呜呜 直接bitset O(n^3/w)QAQ 就是f[i]表示i是否能被搞出来 然后我们先不看 ...

  5. DP题组

    按照顺序来. Median Sum 大意: 给你一个集合,求其所有非空子集的权值的中位数. 某集合的权值即为其元素之和. 1 <= n <= 2000 解: 集合配对,每个集合都配对它的补 ...

  6. atcoder题目合集(持续更新中)

    Choosing Points 数学 Integers on a Tree 构造 Leftmost Ball 计数dp+组合数学 Painting Graphs with AtCoDeer tarja ...

  7. 【AtCoder】AGC020

    A - Move and Win 题解 看两个人相遇的时候谁先手即可,相遇之后第一个移动的人必输 代码 #include <bits/stdc++.h> #define fi first ...

  8. pandas高级操作总结

    1.pandas中的列的分位数 # 查看列的分位数 import pandas as pd # set columns type my_df['col'] = my_df['col'].astype( ...

  9. 【Bitset】重识

    ---------------------------------------------------------------------------- 一题题目: 一题题解: 这个题目哪来入门再好不 ...

随机推荐

  1. vue-cli中vuex IE兼容

    vue2.0 兼容ie9及其以上 vue-cli中使用vuex的项目 在IE中会出现页面空白 控制台报错的情况:我们只需要安装一个插件,然后在main.js中全局引入即可 安装 npm install ...

  2. 批处理,%~d0 cd %~dp0 代表什么意思

    批处理,%~d0 cd %~dp0 代表什么意思   ~dp0 “d”为Drive的缩写,即为驱动器,磁盘.“p”为Path缩写,即为路径,目录cd是转到这个目录,不过我觉得cd /d %~dp0 还 ...

  3. Xshell6破解

    链接: https://pan.baidu.com/s/1P9kMmGdLfpPPxEgUxNXrhw 提取码: s3js

  4. 常用 css html 样式

    CSS基础必学列表 CSS width宽度 CSS height高度 CSS border边框 CSS background背景 CSS sprites背景拼合 CSS float浮动 CSS mar ...

  5. Python系列8之socket

    目录 socket 简单的聊天机器人 简单的ftp上传 粘包问题的解决 一. socket模块 socket,俗称套接字,其实就是一个ip地址和端口的组合.类似于这样的形式(ip,  port),其中 ...

  6. C# 测量程序运行时间

    using System.Diagnostics; Stopwatch watch = new Stopwatch(); watch.Start(); /* 需要测量运行时间的程序 */ watch. ...

  7. Kuernetes-设计架构(二)

    Kubernetes设计架构 Kubernetes集群包含有节点代理kubelet和Master组件(APIs,scheduler.etc),一切都基于分布式的存储系统.Kubernetes架构图: ...

  8. R语言学习笔记(一):mode, class, typeof的区别

    要了解这三个函数的区别,先了解numeric, double与integer. 在r中浮点数有两个名字叫numeric与double. double是指它的类型(type)名字,numeric是指它的 ...

  9. 【Leetcode】413. Arithmetic Slices

    Description A sequence of number is called arithmetic if it consists of at least three elements and ...

  10. 【UE4】二十六、Look at camera 蓝图

    如图,把BP_Cube替换为你需要的对象(如3DUI等)即可.