不知道为什么错了求挑
查看原帖
不知道为什么错了求挑
940317
lightme楼主2024/3/15 21:10
// Problem: 
//     P1541 [NOIP2010 提高组] 乌龟棋
//   
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1541
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<iostream>
#include<algorithm>
//#include<cstdio>
#include<cstring>
#define ll long long 
#define endl '\n'
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>(b);i--)
#define N 355 //1e6+100 
#define M 45
using namespace std;
int n,m,x;
int a[N],b[5],dp[M][M][M][M];
int main(){
	//ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	memset(dp,0,sizeof dp);	
	rep(i,1,n) cin>>a[i];
	rep(i,1,m){
		cin>>x;
		b[x]++;
	}
	dp[0][0][0][0]=a[1];
	rep(x1,0,b[1]){
		rep(x2,0,b[2]){
			rep(x3,0,b[3]){
				rep(x4,0,b[4]){
					int tmp= dp[x1][x2][x3][x4];
					int add= a[x1*1+x2*2+x3*3+x4*4];
					if(x1!=0) tmp=max(tmp,dp[x1-1][x2][x3][x4]+add);
					if(x2!=0) tmp=max(tmp,dp[x1][x2-1][x3][x4]+add);
					if(x3!=0) tmp=max(tmp,dp[x1][x2][x3-1][x4]+add);
					if(x4!=0) tmp=max(tmp,dp[x1][x2][x3][x4-1]+add);
					dp[x1][x2][x3][x4]=tmp;
				}
			}
		}
	}
	cout<<dp[b[1]][b[2]][b[3]][b[4]];
	return 0; 
} 


2024/3/15 21:10
加载中...