蒟蒻不会快读
查看原帖
蒟蒻不会快读
138357
Richard21477楼主2020/6/12 20:21
#include<bits/stdc++.h>
using namespace std;
const int mod=10;
struct ins{
	int l;
	short int a[85];
	bool operator < (ins kkk)const{
		if (l!=kkk.l)
			return l<kkk.l;
		for (int i=l;i>=1;i--){
			if (a[i]!=kkk.a[i])
				return a[i]<kkk.a[i];
		}
		return false;
	}
	ins operator * (ins kkk)const{
		int li=l+kkk.l;
		ins sc03;
		memset(sc03.a,0,sizeof(sc03.a));
		for (int i=1;i<=l;i++)
			for (int j=1;j<=kkk.l;j++){
				int k=i+j-1;
				int op=a[i]*kkk.a[j];
				while (op>0){
					sc03.a[k]+=op%mod;
					op/=mod;
					if (sc03.a[k]>=mod){
						sc03.a[k]-=mod;
						op++;
					}
					k++;
				}
			}
		if (sc03.a[li]==0)
			sc03.l=li-1;
		else
			sc03.l=li;
		return sc03;
	}
	ins operator + (ins kkk){
		int li=max(l,kkk.l);
		ins sc03;
		memset(sc03.a,0,sizeof(sc03.a));
		for (int i=1;i<=li;i++){
			if (i<=l)
				sc03.a[i]+=a[i];
			if (i<=kkk.l)
				sc03.a[i]+=kkk.a[i];
			if (sc03.a[i]>=10){
				sc03.a[i]-=10;
				sc03.a[i+1]++;
			}
		}
		if (sc03.a[li+1]>0)
			sc03.l=li+1;
		else
			sc03.l=li;
		return sc03;
	}
};
ins zero(){
	ins ret;
	ret.l=1;
	ret.a[1]=0;
	return ret;
}
ins make(int x){
	ins ret;
	ret.l=0;
	while (x!=0){
		ret.l++;
		ret.a[ret.l]=x%mod;
		x/=mod;
	}
	return ret;
}
ins pow(int t){
	ins a=make(1),b=make(2);
	while (t>0){
		if ((t&1)!=0)
			a=a*b;
		b=b*b;
		t=t>>1;
	}
	return a;
}
void out(ins ret){
	for (int i=ret.l;i>=1;i--)
		cout<<ret.a[i];
	cout<<endl;
	return;
}
short int read(){
	char in;
	short int ret=0;
	scanf("%hd",&ret);
	return ret;
	
	while(1){
		in=getchar();
		if(in>='0'&&in<='9'){
			ret*=10;
			ret+=in-'0';
		}
		else
			return ret;
	}
}
int main(){
	short int n,m;
	n=read();
	m=read();
	ins ans=zero();
	ins dp[85][85];
	for (int a=1;a<=n;a++){
		short int b;
		ins opp[m+1];
		for (int i=1;i<=m;i++){
			b=read();
			opp[i]=make(b);
		}
		for (int i=1;i<=m;i++)
			for (int j=i+1;j<=m;j++)
				dp[i][j]=zero();
		for (int i=1;i<=m;i++){
			dp[i][i]=opp[i]*pow(m);
			//printf("dp[i][i] ");
			//out(dp[i][i]);
		}
		for (int l=2;l<=m;l++){
			for (int i=1;i+l-1<=m;i++){
				int j=i+l-1;
				ins k1=dp[i][j-1]+pow(m-l+1)*opp[j];
				ins k2=dp[i+1][j]+pow(m-l+1)*opp[i];
				if (k1<k2)
					dp[i][j]=k2;
				else
					dp[i][j]=k1;
				/*if (i==1&&j==3){
					out(dp[i][j-1]);
					out(pow(m-l+1));
					out(opp[j]);
					out(pow(m-l+1)*opp[j]);
					out(dp[i][j-1]+pow(m-l+1)*opp[j]);
					
					out(dp[i+1][j]);
					out(pow(m-l+1));
					out(opp[i]);
					out(pow(m-l+1)*opp[i]);
					out(dp[i+1][j]+pow(m-l+1)*opp[i]);
					out(k1);
					out(k2);
				}*/
			}
		}
		ans=ans+dp[1][m];
		/*for (int i=1;i<=m;i++)
			for (int j=i;j<=m;j++)
			out(dp[i][j]);*/
	}
	out(ans);
	return 0;
}

用scanf就有80分,快读就只有10分 最后俩还是T掉了(自家电脑结果正常)

2020/6/12 20:21
加载中...