您的位置:首页 > 其它

n个数操作k次每次一数乘以x,求所有数或值的最大值 "Or" Game

2015-09-17 11:28 387 查看
http://codeforces.com/contest/579/problem/D

题意

给你n个数,你可以操作k次,使得其中的某一个数乘以x

要求最后得到的所有数的或值最大
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N = 200005;

long long n, k, x;

long long a
, sum
, sum1
;

long long ans, pow;

int main() {
	cin >> n >> k >> x;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	pow = 1;
	for (int i = 0; i < k; ++i) {
		pow *= x;
	}
	sum[0] = 0;
	for (int i = 0; i < n; ++i) {
		sum[i + 1] = sum[i] | a[i];
	}
	sum1
 = 0;
	for (int i = n - 1; i >= 0; --i) {
		sum1[i] = sum1[i + 1] | a[i];
	}
	ans = 0;
	for (int i = 0; i < n; ++i) {
		ans = max(ans, sum[i] | (a[i] * pow) | sum1[i + 1]);
	}
	cout << ans << endl;
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: