[Codefroces 1230D]Marcin and Training Camp

如果011101是其中最多才多艺的一个,为了有人让他不骄傲,必须有011101,111101,011111或111111。选011101的话正好。选111101会傲视011101和他的子集,还得有人压111101才行.

所有最多才多艺的人一定才对出现,而他们的子集可以卑微的加入。 

可以用vector把成对的存起来,(a|b)==b说明a是b子集

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
 
using namespace std;
 
typedef long long LL;
 
LL a[7100];
vector<LL> g;
 
map<LL,LL> tp,cnt;
 
int main() {
    int n;
    scanf("%d",&n);
    for (int i = 1; i <= n; i++) {
    	scanf("%I64d",&a[i]);
    	cnt[a[i]]++;
	}
	for (int i = 1; i <= n; i++) {
		LL b;
    	scanf("%I64d",&b);
    	tp[a[i]] += b;
	}
	LL ans = 0;
	for (int i = 1; i <= n; i++) 
	 if (cnt[a[i]] >= 2) {
	 	LL s = a[i];
	 	/*
	 	for(LL j=s; j; j = (j-1)&s) {
	 		if (!tp.count(j)) continue;
	 		ans += tp[j];
	 		tp[j] = 0;
	 		cnt[j] = 0;
		 }*	
		 ans = ans+tp[0];
         tp[0] = 0;*/
         ans = ans+tp[s];
         tp[s] = cnt[s] = 0;
         g.push_back(s);
	 } 
//cout<<ans;
	 for (int i = 1; i <= n; i++)
	  if(cnt[a[i]] > 0) {
	  //	cout<<a[i]<<"\n";
	 	for (int j = 0; j < g.size(); j++) {
	 	 if ((g[j]|a[i]) == g[j]) {
	 	 	LL s = a[i];
	 	 	ans = ans+tp[s];
            tp[s] = cnt[s] = 0;
	 	 	break;
		  }
	  }
	 }
	printf("%I64d",ans);
    return 0;
}

Marcin is a coach in his university. There are nn students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.

Let's focus on the students. They are indexed with integers from 11 to nn. Each of them can be described with two integers aiai and bibi; bibi is equal to the skill level of the ii-th student (the higher, the better). Also, there are 6060 known algorithms, which are numbered with integers from 00 to 5959. If the ii-th student knows the jj-th algorithm, then the jj-th bit (2j2j) is set in the binary representation of aiai. Otherwise, this bit is not set.

Student xx thinks that he is better than student yy if and only if xx knows some algorithm which yy doesn't know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.

Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?

Input

The first line contains one integer nn (1≤n≤70001≤n≤7000) — the number of students interested in the camp.

The second line contains nn integers. The ii-th of them is aiai (0≤ai<2600≤ai<260).

The third line contains nn integers. The ii-th of them is bibi (1≤bi≤1091≤bi≤109).

Output

Output one integer which denotes the maximum sum of bibi over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值