首页 > 其他 > 详细

The 15-th Beihang University Collegiate Programming Contest (BCPC 2020) - Final I - Poison AND^OR Affection

时间:2021-05-27 16:41:51      阅读:19      评论:0      收藏:0      [点我收藏+]

题链

技术分享图片

做法1 写T了;

这是做法2;

#include <bits/stdc++.h>
using namespace std;
#define ls rt<<1
#define rs rt<<1|1
#define LL long long
#define PI acos(-1.0)
#define eps 1e-8
#define Pair pair<double,double>
// notice
#define mod 998244353 
#define MAXN 1e18
#define MS 2009

LL n,m;
LL a[MS];
struct node{
	int pos;
	LL val;
};
vector<node > vc[MS];
LL dp[MS][MS]; 

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	for(int i=1;i<=n;i++){
		LL t = -1 ,t1 = a[i] ,t2 = a[i];
		for(int j=i-1;j>=1;j--){
			t1 &= a[j];
			t2 |= a[j];
			LL cc = t1^t2;
			if(cc != t){
				t = cc;
				vc[i].push_back({j,cc});
			}
		}
		vc[i].push_back({1,-1});
	}
	//-- 初始化第 1 层信息 
	LL t1 = a[1], t2 = a[1];
	for(int i=2;i<=n;i++){
		t1 &= a[i];
		t2 |= a[i];
		LL cc = t1^t2;
		dp[1][i] = cc;
	}
	//--  计算每一层 
	for(int i=2;i<=m;i++){
		for(int j=i+1;j<=n;j++){ //-- (j<=i)时 dp[i][j] 都设为 0 
			dp[i][j] = dp[i-1][j-1]; //-- 将第 j 个元素作为单个一组 
			for(int k=0;k<vc[j].size()-1;k++){
				if(vc[j][k].pos <= i-1) break;
				dp[i][j] = max(dp[i][j] ,dp[i-1][vc[j][k].pos-1] + vc[j][k].val);
			}
		}
		
		
	}
	cout << dp[m][n] << "\n";
	

	return 0;
}

The 15-th Beihang University Collegiate Programming Contest (BCPC 2020) - Final I - Poison AND^OR Affection

原文:https://www.cnblogs.com/Tecode/p/14817206.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!