[TC14860]SquadConstructor2

题目大意:

有\(n(n<2^m,m\le8)\)个互不相等的数\(v_i\)。从中选取\(k(k\le8)\)个数\(b_i\),求\(\sum_{i=0}^m(\sum_{j=1}^k[b_j\wedge 2^i=2^i])^2\)的最大值。

思路:

一个显然的动态规划\(f[i][s]\)表示选择了\(i\)个数,是否能使得状态为\(s\)。其中状态\(s\)表示\(0\sim m-1\)中每一个二进制位出现次数。显然可以做到\(\mathcal O(n\cdot k\cdot9^m)\)。使用bitset优化,做到\(\mathcal O(\frac{n\cdot k\cdot9^m}\omega)\)。

源代码:

#include<vector>
#include<bitset>
constexpr int M=8,N=1<<M,K=9;
constexpr int pwr[]={1,9,81,729,6561,59049,531441,4782969,43046721};
class SquadConstructor2 {
private:
int b[N];
std::bitset<pwr[M]> f[K];
int sqr(const int &x) const {
return x*x;
}
public:
int teamget(const int &m,const int &k,std::vector<int> v) {
const int n=v.size();
for(register int i=0;i<n;i++) {
for(register int j=0;j<m;j++) {
if(v[i]&(1<<j)) b[i]+=pwr[j];
}
}
f[0][0]=1;
for(register int i=0;i<n;i++) {
for(register int j=k;j;j--) {
f[j]|=f[j-1]<<b[i];
}
}
int ans=0;
for(register int s=0;s<pwr[m];s++) {
if(!f[k][s]) continue;
int tmp=0;
for(register int i=0;i<m;i++) {
tmp+=sqr(s/pwr[i]%9);
}
ans=std::max(ans,tmp);
}
return ans;
}
};

[TC14860]SquadConstructor2的更多相关文章

随机推荐

  1. px,em,rem字体单位

    1.px像素(Pixel).相对长度单位.像素px是相对于显示器屏幕分辨率而言的.(引自CSS2.0手册) 2.em是相对长度单位.相对于当前对象内文本的字体尺寸,em存在值继承问题. 浏览器的默认字 ...

  2. HTTP和HTTPS详解。

    一,HTTP和HTTPS基本概念 深入学习某个东西时,我们先来从维基百科上看看它俩的概念. HTTP:超文本传输协议(英文:HyperText Transfer Protocol,缩写:HTTP)是一 ...

  3. arpspoof dnsspoof中间人攻击

    最近搞了一个监听神器,尽管使用了网卡混杂模式,不过监听到的几乎全是本地流量, 为了获取更多有用的数据,搞一下中间人攻击,最基本的就是arpspoof + IP转发,这样就可以获得局域网内任何人的上网流 ...

  4. Ubuntu中启用关闭Network-manager网络设置问题! 【Server版本】

    在UbuntuServer版本中,因为只存有命令行模式,所以要想进行网络参数设置,只能通过修改/etc/network/interfaces.具体设置方法如下: (1) UbuntuServer 修改 ...

  5. x64dbg

    https://x64dbg.com/ https://github.com/x64dbg/x64dbg https://sourceforge.net/projects/x64dbg/files/s ...

  6. PhysX SDK

    PhysX SDK https://developer.nvidia.com/physx-sdk NVIDIA PhysX SDK Downloads http://www.nvidia.cn/obj ...

  7. 在Caffe中使用 DIGITS(Deep Learning GPU Training System)自定义Python层

    注意:包含Python层的网络只支持单个GPU训练!!!!! Caffe 使得我们有了使用Python自定义层的能力,而不是通常的C++/CUDA.这是一个非常有用的特性,但它的文档记录不足,难以正确 ...

  8. python多进程处理数据

    当我们处理大规模数据如ImageNet的时候,单进程显得很吃力耗时,且不能充分利用多核CPU计算机的资源.因此需要使用多进程对数据进行并行处理,然后将结果合并即可.以下给出的是多进程处理的demo代码 ...

  9. dev....把pivotgridview和chart一起导出

    首先~: 命名空间: using DevExpress.XtraPrinting;using DevExpress.XtraCharts.Native;using DevExpress.XtraPri ...

  10. docker数据管理--数据卷的备份

    /* 先在宿主机创建一个备份的文 件夹, 然后将其以另外一个名字的目录挂载到容器里, 此时不管容器里,或宿主机里做什么操作, 数据都会及时更新,并得到备份. */ [root@localhost ~] ...