[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. base--AuditResult

    //参考base-4.0.2.jar public class AuditResult implements TimeReferable, Serializable //参考api-1.0.0.jar ...

  2. ubuntu tomcat的安装与配置

    一.下载jdk 大概是tomat大部分是由java写的, 所以一开始安装tomcat必须得配置好jdk http://www.oracle.com/technetwork/java/javase/do ...

  3. pdf文件添加到word中

    今天遇到了一个问题,如何把pdf文件添加到word中,而不是只添加图标,下面是解决方案: 1.用word 打开pdf文件: 2.打开word文件: 3.把1中的pdf文件复制粘贴 到2中的word文件 ...

  4. 日常开发技巧:在远程机器上直接使用adb

    背景 嵌入式开发中,开发工作是在远程服务器上进行的.当需要adb推送一个文件到开发板时,则需要重新在本地机器中找到该文件,再执行命令.这样的操作比较麻烦. 下面介绍我的解决方式. sshfs挂载 首先 ...

  5. python基础===Windows环境下使用pip install 安装出错"Cannot unpack file"解决办法

    不知道为什么,加了豆瓣镜像源还是不行 这个命令可以解决! pip install -i http://pypi.douban.com/simple/ --trusted-host pypi.douba ...

  6. sunos kernel src leakrs

    https://github.com/joede/libezV24 https://github.com/ysei/siriusSparcV8 https://github.com/omniti-la ...

  7. xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance(xsi:schemaLocation详解)

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"中xsi的意思是 :本xml文件中要用到某些来自xsi代表的“http:/ ...

  8. sicily 1172. Queens, Knights and Pawns

    Description You all are familiar with the famous 8-queens problem which asks you to place 8 queens o ...

  9. 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6156 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6156 题意:如题. 解法:数位DP,暴力枚举进制之后,就转化成了求L,R区间的回文数的个数,这个直接做 ...

  10. CentOS安装按进程实时统计流量情况工具NetHogs笔记

    CentOS安装按进程实时统计流量情况工具NetHogs笔记 一.概述 NetHogs是一款开源.免费的,终端下的网络流量监控工具,它可监控Linux的进程或应用程序的网络流量.NetHogs只能实时 ...