topcoder srm 694 div1 -3
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的更多相关文章
- Topcoder SRM 643 Div1 250<peter_pan>
Topcoder SRM 643 Div1 250 Problem 给一个整数N,再给一个vector<long long>v; N可以表示成若干个素数的乘积,N=p0*p1*p2*... ...
- Topcoder Srm 726 Div1 Hard
Topcoder Srm 726 Div1 Hard 解题思路: 问题可以看做一个二分图,左边一个点向右边一段区间连边,匹配了左边一个点就能获得对应的权值,最大化所得到的权值的和. 然后可以证明一个结 ...
- topcoder srm 714 div1
problem1 link 倒着想.每次添加一个右括号再添加一个左括号,直到还原.那么每次的右括号的选择范围为当前左括号后面的右括号减去后面已经使用的右括号. problem2 link 令$h(x) ...
- topcoder srm 738 div1 FindThePerfectTriangle(枚举)
Problem Statement You are given the ints perimeter and area. Your task is to find a triangle wi ...
- Topcoder SRM 602 div1题解
打卡- Easy(250pts): 题目大意:rating2200及以上和2200以下的颜色是不一样的(我就是属于那个颜色比较菜的),有个人初始rating为X,然后每一场比赛他的rating如果增加 ...
- Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串
Problem Statement The Happy Letter game is played as follows: At the beginning, several players ...
- Topcoder SRM 584 DIV1 600
思路太繁琐了 ,实在不想解释了 代码: #include<iostream> #include<cstdio> #include<string> #include& ...
- TopCoder SRM 605 DIV1
604的题解还没有写出来呢.先上605的. 代码去practice房间找. 说思路. A: 贪心,对于每个类型的正值求和,如果没有正值就取最大值,按着求出的值排序,枚举选多少个类型. B: 很明显是d ...
- 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)其 ...
随机推荐
- Unity shader学习之Alpha Test的阴影
Alpha Test的阴影, shader如下: // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClip ...
- python pillow
https://www.cnblogs.com/morethink/p/8419151.html#%E7%9B%B4%E6%8E%A5%E6%8F%92%E5%85%A5%E6%8E%92%E5%BA ...
- <6>Lua元表和冒号 self
Lua中没有像C.C++.JAVA中的类概念,面向对象等 ,但我们可以模拟出来 1. Lua中有个很重要的概念元表 设置元表setmetatable()函数 获取元表getmetatable()函数 ...
- Shader2.0常用语义
POSITION: 获取模型顶点的信息.NORMAL: 获取法线信息TEXCOORD(n): 高精度的从顶点传递信息到片段着色器COLOR: 表示低精度从顶点传递信息到片段着色器 ...
- Java集合-----List详解
List中的元素是有序排列的而且可重复 1.LinkedList LinkedList是非线程安全的,底层是基于双向链表实现的 LinkedList常用方法: toArray() ...
- Sqrt Bo (水题)
#include<bits/stdc++.h> using namespace std; ], comp; ]; int main(){ arr[] = 1LL; ; i < ; i ...
- ReactiveCocoa(II)
RAC类关系图: RAC 信号源: 需要导入的头文件: import ReactiveCocoa import Result import ReactiveSwift 冷信号 //1.冷信号 let ...
- 用python进行wifi密码生成
随着无线网络的不断发展,几乎所有场合都会覆盖WIFI信号,无论是公共地点还是家庭之中.众所周知,目前WIFI普遍的认证方式为wpa2,这种认证方式安全性相当不错,但由于人们设置密码时的随意性和固有思维 ...
- js中时间戳转换成时间格式
js中时间戳转换成时间格式, // 时间戳转换成时间格式 var formatDate = function(date){ date = new Date(date); var y=date.getF ...
- notepad 正则表达式 复制 文本