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)其 ...
随机推荐
- NHibernate初学者指南系列文章导航
NHibernate初学者指南系列文章导航 前面的话 经过三个多周的时间,终于将这个系列完成了,谢谢大家的关注和支持,有很多不足之处还望大家包涵. 本系列参考的书籍为NHibernate 3 Be ...
- CSS3 transition-timing-function 深入理解和技巧
基础 语法: transition-timing-function : ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier( ...
- c# 集合中有数字、字符的Orderby排序
string[] things= new string[] { "105", "101", "102", "103", ...
- Python -- print(dataframe)时,省略部分列。
import pandas as pd # 导入后加入以下列,再显示时显示完全. pd.set_option('display.max_rows',500) pd.set_option('displa ...
- bzoj4445 小凸想跑步
题目链接 半平面交,注意直线方向!!! 对于凸包上任意一条边$LINE(p_i,p_{i+1})$都有$S_{\Delta{p_i} {p_{i + 1}}p} < S_{\Delta{p_0} ...
- Inernet TLS协议注册表 开启
IE高级配置中,存在SSL支持协议,例如SSL TLS. 其在注册表的路径为:HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\I ...
- APIClound 弹出层 Frame
JS api.openFrame({ name: 'showPic', url: './showPic.html', rect: { // x: api.pageParam.marginBottom, ...
- Service_name 和Sid的区别
Service_name:该参数是由oracle8i引进的.在8i以前,使用SID来表示标识数据库的一个实例,但是在Oracle的并行环境中,一个数据库对应多个实例,这样就需要多个网络服务名,设置繁琐 ...
- Java用Jackson遍历json所有节点
<!-- jackson begin --> <dependency> <groupId>com.fasterxml.jackson.core</groupI ...
- 忘记MySQL root密码,如何不重启修改
说个前提:mysqld可以处理kill命令发送的信号,如SIGHUP.SIGTERM,SIGHUP信号产生的行为类似于flush命令. 不重启找回root密码首先需要有个较低权限的账号,比如可以修改t ...