Mathematical Curse - 题库 - 计蒜客
记得是要记录最小值,max有可能是从最小反转zu过来
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#define mem(a,x) memset(a,x,sizeof(a))
#define s1(x) scanf("%d",&x)
#define s2(x,y) scanf("%d%d",&x,&y)
#define s3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s4(x,y,z,k) scanf("%d%d%d%d",&x,&y,&z,&k)
#define ff(a,n) for(int i = 0 ; i < n; i++) scanf("%d",a+i)
#define ls 2*rt
#define rs 2*rt+1
#define lson ls,L,mid
#define rson rs,mid+1,R
#define ll long long
using namespace std;
typedef pair<int,int> pii;
//inline ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&(-x);return res;}
//inline void add(int x,int d){while(x<=n)c[x]+=d,x+=x&(-x);}
//int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b);}
const ll inf = 1e18;
const int mx = 1e3+6;
//const int mod = 1e9+6;
int n,m,k,num[mx];
ll Max[7],Min[7];
char s[10];
ll calc(ll a,int b, int x){
if( s[x] == '+')
return a+b;
if( s[x] == '-')
return a-b;
if( s[x] == '*')
return a*b;
if( s[x] == '/')
return a/b;
}
int main(){
// freopen("C:\\Users\\black\\Desktop\\in.txt","r",stdin);
int T=10; scanf("%d",&T);
while(T--){
s3(n,m,k);
for(int i = 0; i < n; i++){
scanf("%d",num+i);
}
scanf("%s",s+1);
for(int i = 0; i <6; i++){
Max[i] = -inf;
Min[i] = inf;
}
Max[0]=Min[0]=k;
// cout<<Max[0]<<endl;
ll t1,t2;
for(int i = 0; i < n; i++){
for(int k = m; k >= 1; k--){
//printf("k =%d %lld\n",k,Max[k-1]);
if(Max[k-1]!=-inf){
// puts("jin");
t1 = calc(Max[k-1],num[i],k);
t2 = calc(Min[k-1],num[i],k);
Max[k] = max(max(t1,t2),Max[k]);
Min[k] =min(min(t1,t2),Min[k]);
//printf("k =%d %lld\n",k,Max[k]);
}
}
}
printf("%lld\n",Max[m]);
}
return 0;
}