这题治好了我的快读恐惧症,让我理解了cin的力量
cin,照亮世界!
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
int n,ans=-inf;
int a[105];
int f[150][150],g[150][150];
char c[105];
int max(int x,int y){return (x>y)?(x):(y);}
int min(int x,int y){return (x<y)?(x):(y);}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>c[i]>>a[i];
a[n+i]=a[i];
c[n+i]=c[i];
}
for(int i=1;i<=(n<<1);i++)for(int j=1;j<=(n<<1);j++)f[i][j]=-inf,g[i][j]=inf;
for(int i=1;i<=(n<<1);i++)f[i][i]=g[i][i]=a[i];
for(int len=2;len<=n;len++){
for(int i=1,j=len;j<=(n<<1);i++,j++){
for(int k=i;k<j;k++){
if(c[k+1]=='x'){
f[i][j]=max(f[i][j],max(f[i][k]*f[k+1][j],max(g[i][k]*g[k+1][j],max(f[i][k]*g[k+1][j],g[i][k]*f[k+1][j]))));
g[i][j]=min(g[i][j],min(f[i][k]*f[k+1][j],min(g[i][k]*g[k+1][j],min(f[i][k]*g[k+1][j],g[i][k]*f[k+1][j]))));
}else if(c[k+1]=='t'){
f[i][j]=max(f[i][j],f[i][k]+f[k+1][j]);
g[i][j]=min(g[i][j],g[i][k]+g[k+1][j]);
}
}
}
}
for(int i=1;i<=n;i++)ans=max(ans,f[i][i+n-1]);
cout<<ans<<'\n';
for(int i=1;i<=n;i++)if(f[i][i+n-1]==ans)cout<<i<<' ';
return 0;
}
标签:150,return,int,P4342,inf,105
From: https://www.cnblogs.com/zan-mei-tai-yang/p/18470625