1 solutions
-
-1
#include <bits/stdc++.h> using namespace std; #define N (int)(85) const int B=1e4; int n,m,a[N]; struct bg { int num[505],len; bg() { memset(num,0,sizeof(num)); len=0; } void print() { cout << num[len]; for(int i=len-1; i>0; i--) { if(!num[i])cout << "0000"; else { for(int k=10; knum[i]<B; k=10) cout << "0"; cout << num[i]; } } } } f[N][N],base[N],ans;
bg operator+(bg a,bg b) { bg c; c.len=max(a.len,b.len); int jw=0; for(int i=1; i<=c.len; i++) { c.num[i]=a.num[i]+b.num[i]+jw; jw=c.num[i]/B; c.num[i]%=B; } if(jw>0) c.num[++c.len]=jw; return c; } bg operator*(bg a,int b) { bg c; c.len=a.len; int jw=0; for(int i=1; i<=c.len; i++) { c.num[i]=a.num[i]*b+jw; jw=c.num[i]/B; c.num[i]%=B; } while(jw>0) c.num[++c.len]=jw%B,jw/=B; return c; } bg max(bg a,bg b) { if(a.len!=b.len)return a.len<b.len?b:a; for(int i=a.len; i>0; i--) if(a.num[i]!=b.num[i]) return a.num[i]>b.num[i]?a:b; return a; } void init() { basnum[1]=1; base[0].len=1; for(int i=1; i<=m+2; i++) base[i]=base[i-1]*2; } signed main() { // freopen("check.in","r",stdin); // freopen("check.out","w",stdout); cin >> n >> m; init(); memset(f,0,sizeof(f)); for(int i=1; i<=m; i++) cin >> a[i]; for(int i=1; i<=m; i++) for(int j=m; j>=i; j--) { f[i][j]=max(f[i][j],f[i-1][j]+base[m-i-1]*a[i-1]); f[i]max(f[i][j],f[i][j+1]+base[m-j+i-1]*a[j+1]); } for(int i=1; i<=m; i++) mx=max(mx,f[i][i]+base[m]*a[i]); res=res+mx; return 0; } //虽然但是最好别抄
- 1
Information
- ID
- 5
- Time
- 1000ms
- Memory
- 125MiB
- Difficulty
- 4
- Tags
- # Submissions
- 8
- Accepted
- 5
- Uploaded By