卡常求助QWQ
查看原帖
卡常求助QWQ
99643
陈刀仔楼主2021/2/9 21:51

江郎才尽了

#include <bits/stdc++.h>
using namespace std;
inline int read(){
	int s=0,w=1,ch=getchar();
	while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
	while(isdigit(ch)){s=(s<<3)+(s<<1)+ch-48;ch=getchar();}
	return s*w;
}
const int maxn=5e4+50,mod=1e9+7;
int n,m,a[11][maxn];
string str;
void init(){
	cin>>n>>m;
	for(int i=0;i<m;i++)
		for(int j=1;j<=n;j++)a[i][j]=read();
	getline(cin,str);
	getline(cin,str);
}
int plp[maxn],tot;
int ans=0,tp=0,g[1024]={0},rk[11]={0};
struct node{
	int a[3];
	node(){memset(a,0,sizeof(a));}
	void clear(){memset(a,0,sizeof(a));}
}stk[maxn];
void dealstr(){
	plp[++tot]=str[0]-'0';
	for(int i=1;i<str.size();i++){
			if(str[i]=='>')plp[++tot]=-1;
			if(str[i]=='<')plp[++tot]=-2;
			if(str[i]=='?')plp[++tot]=-5;
			if(str[i]=='(')plp[++tot]=-3;
			if(str[i]==')')plp[++tot]=-4;
			if(isdigit(str[i]))plp[++tot]=str[i]-'0';
	}
}
void domod(int &x){if(x>mod)x-=mod;}
void merge(int x,int y,int op){
	int f[11]={0};
	if(op==-1){
		for(int i=1;i<=2;i++)//x
			for(int j=1;j<=2;j++)//y
			{
				int m1=max(i,j);
				f[m1]+=1ll*stk[x].a[i]*stk[y].a[j]%mod;
				domod(f[m1]);
			}
	}
	if(op==-2){
		for(int i=1;i<=2;i++)//x
			for(int j=1;j<=2;j++)//y
			{
				int m2=min(i,j);
				f[m2]+=1ll*stk[x].a[i]*stk[y].a[j]%mod;
				domod(f[m2]);
			}
	}
	if(op==-5){
		for(int i=1;i<=2;i++)//x
			for(int j=1;j<=2;j++)//y
			{
				int m1=max(i,j),m2=min(i,j);
				f[m1]+=1ll*stk[x].a[i]*stk[y].a[j]%mod;
				domod(f[m1]);
				f[m2]+=1ll*stk[x].a[i]*stk[y].a[j]%mod;
				domod(f[m2]);
			}
	}
	for(int i=1;i<=2;i++)stk[x].a[i]=f[i];
}
void solve(int st){
	tp=0;
	int tmp;
	for(register int ttt=1;ttt<=tot;ttt++){
		tmp=plp[ttt];
		if(tmp==-1||tmp==-2||tmp==-3||tmp==-5){stk[++tp].clear();stk[tp].a[0]=tmp;continue;}
		if(tmp==-4){
			stk[tp-1]=stk[tp];
			tp--;
			register int p=tp;
			for(p=tp;p>=1&&stk[p].a[0]!=-3;p--);
			p++;
			for(int i=p+2;i<=tp;i+=2){
				int op=stk[i-1].a[0];
				merge(p,i,op);
			}
			tp=p;
			continue;
		}
		tp++;
		stk[tp].clear();
		stk[tp].a[rk[tmp]]=1;
		if(stk[tp-1].a[0]==-1||stk[tp-1].a[0]==-2||stk[tp-1].a[0]==-5){
			int op=stk[tp-1].a[0];
			merge(tp-2,tp,op);
			tp-=2;
		}
	}
	g[st]=stk[tp].a[2];
}
void get(){
	dealstr();
	for(register int i=1;i<(1<<m);i++){
		for(int j=0;j<m;j++){
			if(i&(1<<j))rk[j]=2;
			else rk[j]=1;
		}
		solve(i);
//		cout<<"***"<<endl;
	}
	
	for(int i=1;i<=n;i++){
		int b[11];
		for(int j=0;j<m;j++)b[j]=a[j][i];
		sort(b,b+m);
		for(int j=0;j<m;j++){
			int st=0;
			for(int k=0;k<m;k++){
				if(a[k][i]>=b[j])st|=(1<<k);
			}
			if(j==0)ans+=1ll*b[j]*g[st]%mod,domod(ans);
			else ans+=1ll*(b[j]-b[j-1])*g[st]%mod,domod(ans);
		}
	}
	cout<<ans<<endl;
	exit(0);
}
signed main(){
//	freopen("expr15.in","r",stdin);
	init();
	get();
	return 0;
}
/*
3 3
4 3 2
2 3 1
2 3 3
1?0>2?0
*/
2021/2/9 21:51
加载中...