Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
32724 | LYLAKIOI | 【J】序列 | C++ | 通过 | 100 | 169 MS | 2060 KB | 1648 | 2024-09-27 13:19:57 |
//WuJue,Start!! #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; const int maxn=1e6+10,V=1e5; const ll mod=(1e13)+37; inline ll read(){ ll x=0;short t=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();} while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; }int n,p,a[125],c[125];ll v[125][125]; map<ll,ll>dp; struct node { int d[125]; ll hsh(){ ll res=0;for(int i=1;i<=n;++i)res=(res*1ll*(c[i]+1)%mod+d[i])%mod; return res; } }; int gcd(int a,int b){ return ((!b)?a:gcd(b,a%b)); }int lcm(int a,int b){ return a*b/gcd(a,b); }ll ss; void upd(int l,int r){ for(int i=l;i<=r-1;++i)ss+=lcm(a[i],a[r])*2; ss+=a[r]; }ll calc(node &st){ ll h=st.hsh(); if(!h)return 0; if(dp.count(h))return dp[h]; ll res=-1e9; int pos=0;for(int i=1;i<=n;++i)pos=pos+st.d[i]*i; for(int i=1;i<=n;++i){ if(st.d[i]>0&&pos>=i){ st.d[i]--; res=max(res,calc(st)+v[pos-i+1][pos]); st.d[i]++; } }return dp[h]=res; }void slv(){ node lim; n=read();for(int i=1;i<=n;++i)a[i]=read();for(int i=1;i<=n;++i)c[i]=read(),lim.d[i]=c[i]; for(int i=1;i<=n;++i){ ss=0; for(int j=i;j<=n;++j)upd(i,j),v[i][j]=ss; }cout<<calc(lim)<<'\n'; }void tslv(){ int t=read();while(t--)slv(); }int main(){ //freopen("array.in","r",stdin); //freopen("array.out","w",stdout); //freopen("1.in","r",stdin),freopen("1.out","w",stdout); slv(); fclose(stdin); fclose(stdout); return 0; }