玄关求调
查看原帖
玄关求调
590675
A1ex_5yn7ax楼主2025/1/13 16:28
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[81][81],dp[81][81],ans,cf2[81]={1};
int main(){
    cin>>n>>m;
    for(int i=1;i<=63;i++) cf2[i]=cf2[i-1]*2;
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
    		cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		dp[2][m]=2*a[i][1],dp[1][m-1]=2*a[i][m];
		long long maxn=-1;
		for(int st=m-3;st>=0;st--){
			for(int j=1;j+st<=m;j++){
				if(j+st+1<=m&&j-1>=1) dp[j][j+st]=max(dp[j][j+st+1]+(a[i][j+st+1]*cf2[m-st-1]),dp[j-1][j+st]+(a[i][j-1]*cf2[m-st-1]));
				else if(j+st+1<=m) dp[j][j+st]=dp[j][j+st+1]+(a[i][j+st+1]*cf2[m-st-1]);
				else if(j-1>=1) dp[j][j+st]=dp[j-1][j+st]+(a[i][j-1]*cf2[m-st-1]);
				maxn=max(maxn,dp[j][j+st]);
			}
		
		} 
		for(int j=1;j<=m;j++) maxn=max(maxn,dp[j][j]+(a[i][j]*cf2[m]));
		ans+=maxn;
	}
	cout<<ans;
    return 0;
}

这个是没用int128的 60分

#include<bits/stdc++.h>
#define int __int128
#undef int
using namespace std;
int n,m,a[81][81],dp[81][81],ans,cf2[81]={1};
inline void read(int &n){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    n=x*f;
}
inline void print(int n){
    if(n<0){
        putchar('-');
        n*=-1;
    }
    if(n>9) print(n/10);
    putchar(n % 10 + '0');
}
int main(){
    read(n),read(m);
    for(int i=1;i<=63;i++) cf2[i]=cf2[i-1]*2;
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
    		read(a[i][j]);
		}
	}
	for(int i=1;i<=n;i++){
		dp[2][m]=2*a[i][1],dp[1][m-1]=2*a[i][m];
		int maxn=-1;
		for(int st=m-3;st>=0;st--){
			for(int j=1;j+st<=m;j++){
				if(j+st+1<=m&&j-1>=1) dp[j][j+st]=max(dp[j][j+st+1]+(a[i][j+st+1]*cf2[m-st-1]),dp[j-1][j+st]+(a[i][j-1]*cf2[m-st-1]));
				else if(j+st+1<=m) dp[j][j+st]=dp[j][j+st+1]+(a[i][j+st+1]*cf2[m-st-1]);
				else if(j-1>=1) dp[j][j+st]=dp[j-1][j+st]+(a[i][j-1]*cf2[m-st-1]);
				maxn=max(maxn,dp[j][j+st]);
			}
		
		} 
		for(int j=1;j<=m;j++) maxn=max(maxn,dp[j][j]+(a[i][j]*cf2[m]));
		ans+=maxn;
	}
	print(ans);
    return 0;
}

这个用了int128反而40分。。。求调教

2025/1/13 16:28
加载中...