求助,RE了QWQ
查看原帖
求助,RE了QWQ
672837
DaShabby楼主2023/7/13 16:55
#include<bits/stdc++.h>
#define x first
#define y second
#define lson node<<1
#define rson node<<1|1
using namespace std;
typedef long long ll;
const int maxn=5e5+34;
__int128 a[100];//,b[maxn],vis[maxn],idx,tot;

__int128 dp[100][100];
__int128 read(){
	__int128 res=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch)){
		res=res*10+ch-'0';
		ch=getchar();
	}
	return res;
}
void write(__int128 x){
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
__int128 quick_pow(__int128 x,ll y){
	__int128 res=1;
	x=2;
	while(y){
		if(y&1)res=res*x;
		x=x*x;
		y>>=1; 
	}
	return res;
}
__int128 dfs(int l,int r,int n){
	if(dp[l][r])return dp[l][r];
	dp[l][r]=max(dfs(l,r-1,n)+a[r]*quick_pow(2,(n-r+l)),dfs(l+1,r,n)+a[l]*quick_pow(2,(n-r+l)));
	return dp[l][r];
}
void work(){
	int n,m,u,v,w;
	scanf("%d%d",&m,&n);
	__int128 ans=0;
	while(m--){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++)dp[i][j]=0;
		}
		for(int i=1;i<=n;i++)a[i]=read(),dp[i][i]=a[i]*quick_pow(2,n);
//		for(int i=1;i<=n;i++)write(dp[i][i]);putchar(' ');
		ans+=dfs(1,n,n);
	}
	write(ans);
	putchar('\n');
}
int main()
{
	int t=1;
//	scanf("%d",&t);
	while(t--)
	work();
	return 0;
} 
2023/7/13 16:55
加载中...