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. 《2017年Q2中国城市研究报告

    根据百度慧眼团队发布的<2017年Q2中国城市研究报告>,2017年第二季度人口吸引力排名前五的城市与第一季度相同,深圳继续保持第一的领先位置.

  2. vbs调用bat 隐藏bat运行时的黑框

    //新建文本文件 ,保存为后缀为bat.如:startBAT.vbs public const vbQuote="""" temp="C:\A_WOR ...

  3. C# 对数据库操作的帮助类SQLHelper.cs

    using System; using System.Collections.Generic; using System.Configuration; using System.Data; using ...

  4. MindMaster学习笔记

    参考博客 http://blog.sina.com.cn/u/6406591976 作者名叫“MindMaster思维导图的博客 ”写了一系列关于思维导图的博客,可以去学习下. 1.其中有一篇比较详细 ...

  5. Unity之Vector3.SignedAngle实现

    如代码: float angle = Vector3.Angle(v1, v2); angle *= Mathf.Sign(Vector3.Cross(v1, v2).y);

  6. Unity shader学习之半兰伯特光照模型

    半兰伯特光照模型,为Valve公司在开发游戏<半条命>时提出的一种技术,用于解决漫反射光无法到达区域无任凭明暗变化,丢失模型细节表现的问题. 其公式如下: Cdiffuse = Cligh ...

  7. Beta阶段冲刺前计划与安排

    凡事预则立,在Beta开始前,以小组为单位,在敏捷冲刺前发布一篇博客,描述: 1. 介绍小组新加入的成员,Ta担任的角色. 新加入的成员是丁蓉同学,在本团队中担任前端设计. 原因:在之前的团队中,她就 ...

  8. Math对象属性

    2018-11-28 11:18:46

  9. xpath ,css

    https://docs.scrapy.org/en/latest/intro/tutorial.html xpath @选择属性  .当前目录下选择 //任意路径选择 /bookstore/book ...

  10. codeforces 768c Jon Snow And His Favourite Number

    题意: 给出一个数列,和一种操作,以及两个数x和k. 这个操作有两个步骤: 首先把这个数列按照升序排序,然后把所有奇数位上的数字与x异或. 问执行k次操作之后,这个数列的最大值和最小值是多少. 思路: ...