1、给出$n$个数字,将其分成三个非空的组,每组的权值为该组所有数字的抑或。选择一种分法使得三组的权值和最大?

思路:记录前两组的权值且三组有没有数字时第三组的值。(当前两组的值知道时第三组的权值是确定的,因为三组的抑或值是确定的)

#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <set>
#include <vector>
#include <time.h>
#include <queue>
#include <stack>
#include <map>
#include <assert.h>
using namespace std; int f[2][256][256][8]; class TrySail
{
public:
int get(vector<int> A)
{
int pre=0,cur=1;
memset(f[pre],-1,sizeof(f[pre]));
f[0][0][0][0]=0;
for(int i=0;i<(int)A.size();++i)
{
memset(f[cur],-1,sizeof(f[cur]));
const int w=A[i];
for(int b=0;b<256;++b) {
for(int c=0;c<256;++c) {
for(int d=0;d<8;++d) {
int k=f[pre][b][c][d];
if(k==-1) continue;
f[cur][b^w][c][d|4]=k;
f[cur][b][c^w][d|2]=k;
f[cur][b][c][d|1]=k^w;
}
}
}
pre^=1;
cur^=1;
}
int ans=0;
for(int a=0;a<256;++a) {
for(int b=0;b<256;++b) {
if(f[pre][a][b][7]!=-1) {
ans=max(ans,f[pre][a][b][7]+a+b);
}
}
}
return ans;
}
};

  

2、给出$n*m$的只包含'A'到'Z'的字符矩阵。对于一个列的集合$S$,如果任意两行$i,j$在$S$上不完全相同,称$S$可以区分所有行。问有多少种列的子集可以区分所有行?$n\leq 1000,m\leq 20$

思路:首先,找到哪些列的子集不能区分所有行。令$f[s]=1$表示集合$s$不能区分所有行,那么所有的$s$^$2^{k}$都不能区分。其中$k$满足$s$&$2^{k}\neq 0$。

#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <set>
#include <vector>
#include <time.h>
#include <queue>
#include <stack>
#include <map>
#include <assert.h>
using namespace std; int f[1<<20]; class DistinguishableSetDiv1
{ public:
int count(vector<string> A)
{ int n=A.size();
int m=A[0].size(); memset(f,0,sizeof(f));
for(int i=0;i<n;++i) for(int j=i+1;j<n;++j)
{
int s=0;
for(int k=0;k<m;++k) if(A[i][k]==A[j][k]) s|=1<<k;
f[s]=1;
}
int ans=0;
for(int i=(1<<m)-1;i>=0;--i)
{
if(f[i])
{
for(int k=0;k<m;++k) if(i&(1<<k)) f[i^(1<<k)]=1;
}
else ++ans;
}
return ans;
}
};

  

topcoder srm 694 div1 -3的更多相关文章

  1. Topcoder SRM 643 Div1 250<peter_pan>

    Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...

  2. Topcoder Srm 726 Div1 Hard

    Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...

  3. topcoder srm 714 div1

    problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...

  4. topcoder srm 738 div1 FindThePerfectTriangle(枚举)

    Problem Statement      You are given the ints perimeter and area. Your task is to find a triangle wi ...

  5. Topcoder SRM 602 div1题解

    打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...

  6. Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串

    Problem Statement      The Happy Letter game is played as follows: At the beginning, several players ...

  7. Topcoder SRM 584 DIV1 600

    思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...

  8. TopCoder SRM 605 DIV1

    604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...

  9. topcoder srm 575 div1

    problem1 link 如果$k$是先手必胜那么$f(k)=1$否则$f(k)=0$ 通过对前面小的数字的计算可以发现:(1)$f(2k+1)=0$,(2)$f(2^{2k+1})=0$,(3)其 ...

随机推荐

  1. webpack 解决跨域问题

    一.webpack 内置了 http-proxy-middleware 可以解决 请求的 URL 代理的问题 安装:npm install --save http-proxy-middleware 二 ...

  2. programmatically detect whenever test run is in debug mode

    if (System.Diagnostics.Debugger.IsAttached)    // code or timeout value when running tests in debug ...

  3. linux网卡eth1如何修改为eth0

    ifconfig看到的ip不是我想要的ip,而且显示的第一块网卡也是eth1 ,这明显是有问题的, vim /etc/sysconfig/network-script/ifcfg-eth0 看到的ip ...

  4. wordpress学习(三)-----add_action动作钩子和add_filter()过滤器钩子

    <?php echo "<h2>高级教程add_action动作和add_filter()过滤器</h2><br/>"; //1.学会使用 ...

  5. SiteCore Experience Analytics-体验分析

    体验分析   Sitecore Experience Analytics为营销人员和营销分析师提供仪表板和报告,以识别从其网站和可能的其他外部数据源收集的体验数据的模式和趋势. 体验分析报告示例:   ...

  6. Maven的配置指南

    Maven的配置指南  配置Maven Maven配置发生在3个级别: 项目 - 大多数静态配置发生在pom.xml中 安装 - 这是Maven安装时发生的一次性的配置过程 用户 - 这是Maven提 ...

  7. jQuery选择器--selector1,selector2,selectorN和ancestor descendant

        selector1,selector2,selectorN 概述 将每一个选择器匹配到的元素合并后一起返回.你可以指定任意多个选择器,并将匹配到的元素合并到一个结果内 参数 selector1 ...

  8. 关于poi导出excel方式HSSFWorkbook(xls).XSSFWorkbook(xlsx).SXSSFWorkbook.csv的总结

    1.HSSFWorkbook(xls) import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermo ...

  9. .net中的集合

    集合命令空间: 命令空间:类型逻辑上的分类 System.Collections  非泛型集合 System.Collections.Generic 泛型集合 集合内部存数据,实际上都是存到了数组里. ...

  10. django中orm的批量操作

    ORM批量操作 数据模型定义 from django.db import models class Product(models.Model): name = models.CharField(max ...