为什么会TLE???
查看原帖
为什么会TLE???
1037981
封禁用户楼主2023/8/17 20:07

快读快输都用上了

#include<bits/stdc++.h>
#define int long long
using namespace std;
int a,b,c,d[22][22][22];
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
inline void write(int x){
	if(!x) putchar('0');
	char F[200];
	int tmp=x>0?x:-x;
	if(x<0) putchar('-');
	int cnt=0;
	while(tmp>0){
		F[cnt++]=tmp%10+'0';
		tmp/=10;
	}
	while(cnt>0) putchar(F[--cnt]);
}
inline int w(int a,int b,int c){
	if(a<=0||b<=0||c<=0) return 1;
	else if(d[a][b][c]) return d[a][b][c];
	else if(a>20||b>20||c>20) return d[a][b][c]=w(20,20,20);
	else if(a<b&&b<c) return d[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
    else return d[a][b][c]=w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
}
signed main(){
    while(1){
    memset(d,0,sizeof(d));
	  a=read(),b=read(),c=read();
	  if(a==-1&&b==-1&&c==-1) break;
      printf("w(");
      write(a);
      printf(", ");
      write(b);
      printf(", ");
      write(c);
      printf(") = ");
      if(a>20) a=21;
      if(b>20) b=21;
      if(c>20) c=21;
      write(w(a,b,c));
      cout<<endl;
    }
}
2023/8/17 20:07
加载中...