#include <iostream.h>
# include<string>
# include<fstream.h>
# include<stdlib.h>
//using namespace std;
#define NMAX 100
int N,m[NMAX+1][NMAX+1][2],v[NMAX+1],pathmove[NMAX];
char op[NMAX+1];
char firstmove[];
void MIN_MAX(int n,int i,int s,int j,int &minf,int &maxf)
{
int e[5];
int a=m[i][s][0],
b=m[i][s][1],
r=(i+s-1)%n+1,
c=m[r][j-s][0],
d=m[r][j-s][1];
if(op[r]=='t')
{
minf=a+c;
maxf=b+d;
}
else
{
e[1]=a*c;
e[2]=a*d;
e[3]=b*c;
e[4]=d*b;
minf=e[1];
maxf=e[1];
for(int r=2;r<N;r++)
{
if(minf>e[r])minf=e[r];
if(maxf<e[r])maxf=e[r];
}
}
}
int ploy_max(int n)
{
int minf,maxf;
for(int j=2;j<=n;j++)
{
for(int i=1;i<=n;i++)
{
for(int s=1 ;s<j;s++)
{
MIN_MAX(n,i,s,j,minf,maxf);
if(m[i][j][0]>minf)
m[i][j][0]=minf;
if(m[i][j][1]<maxf)
m[i][j][1]=maxf;
}
}
}
int temp=m[1][n][1];
for(int i=2 ;i<=n; i++)
{
if(temp<m[i][n][1])
temp=m[i][n][1];
}
return temp;
}
int move(int n,int temp)
{
static int p=0;
for (int k = 1; k <= n; k++)
{
if(temp==m[k][n][1])
{
pathmove[p++]=k;
}
}return p;
}
void main()
{
ifstream infile("IN.txt",ios::in|ios::nocreate);
if(!infile)
{
cout<<"不能打开文件\n";
return;
}
int temp;
char temp2;
infile>>temp;
N=temp;
cout<<N<<endl;
for(int i=1; i<=N; i++)
{
infile>>temp2;
op[i]=temp2;
infile>>temp;
v[i]=temp;
cout<<op[i]<<" "<<v[i]<<" ";
m[i][1][0]=v[i];
m[i][1][1]=v[i];
}
infile.close();
cout<<endl;
int p=ploy_max(N);
cout<<p<<endl;
int fmove=move(N,p);
for(int j=0;j<fmove;j++)
cout<<pathmove[j]<<" ";
ofstream outfile("OUT.txt");
if(!outfile)
{
cout<<"不能打开文件\n";
return;
}
outfile<<p<<"\n";
for(int l=0;l<fmove;l++)
outfile<<pathmove[l]<<" ";
outfile.close();
}
# include<string>
# include<fstream.h>
# include<stdlib.h>
//using namespace std;
#define NMAX 100
int N,m[NMAX+1][NMAX+1][2],v[NMAX+1],pathmove[NMAX];
char op[NMAX+1];
char firstmove[];
void MIN_MAX(int n,int i,int s,int j,int &minf,int &maxf)
{
int e[5];
int a=m[i][s][0],
b=m[i][s][1],
r=(i+s-1)%n+1,
c=m[r][j-s][0],
d=m[r][j-s][1];
if(op[r]=='t')
{
minf=a+c;
maxf=b+d;
}
else
{
e[1]=a*c;
e[2]=a*d;
e[3]=b*c;
e[4]=d*b;
minf=e[1];
maxf=e[1];
for(int r=2;r<N;r++)
{
if(minf>e[r])minf=e[r];
if(maxf<e[r])maxf=e[r];
}
}
}
int ploy_max(int n)
{
int minf,maxf;
for(int j=2;j<=n;j++)
{
for(int i=1;i<=n;i++)
{
for(int s=1 ;s<j;s++)
{
MIN_MAX(n,i,s,j,minf,maxf);
if(m[i][j][0]>minf)
m[i][j][0]=minf;
if(m[i][j][1]<maxf)
m[i][j][1]=maxf;
}
}
}
int temp=m[1][n][1];
for(int i=2 ;i<=n; i++)
{
if(temp<m[i][n][1])
temp=m[i][n][1];
}
return temp;
}
int move(int n,int temp)
{
static int p=0;
for (int k = 1; k <= n; k++)
{
if(temp==m[k][n][1])
{
pathmove[p++]=k;
}
}return p;
}
void main()
{
ifstream infile("IN.txt",ios::in|ios::nocreate);
if(!infile)
{
cout<<"不能打开文件\n";
return;
}
int temp;
char temp2;
infile>>temp;
N=temp;
cout<<N<<endl;
for(int i=1; i<=N; i++)
{
infile>>temp2;
op[i]=temp2;
infile>>temp;
v[i]=temp;
cout<<op[i]<<" "<<v[i]<<" ";
m[i][1][0]=v[i];
m[i][1][1]=v[i];
}
infile.close();
cout<<endl;
int p=ploy_max(N);
cout<<p<<endl;
int fmove=move(N,p);
for(int j=0;j<fmove;j++)
cout<<pathmove[j]<<" ";
ofstream outfile("OUT.txt");
if(!outfile)
{
cout<<"不能打开文件\n";
return;
}
outfile<<p<<"\n";
for(int l=0;l<fmove;l++)
outfile<<pathmove[l]<<" ";
outfile.close();
}