lyq123bc @ 2024-07-04 20:45:17
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<deque>
#include<set>
#include<map>
using namespace std;
typedef int64_t ll;
const int N=1e5+10;
ll A[25][25][25],B[25][25][25];
bool visa[25][25][25],visb[25][25][25];
ll w(ll a,ll b,ll c)
{
if(a<=0||b<=0||c<=0) return 1;
if(a>20||b>20||c>20) return w(20,20,20);
if(a<b&&b<c)
{
if(visa[a][b][c]) return A[a][b][c];
A[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
visa[a][b][c]=1;
return A[a][b][c];
}
if(visb[a][b][c]) return B[a][b][c];
B[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);
visb[a][b][c]=1;
return B[a][b][c];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll a,b,c;
for(int i=1;1;++i)
{
cin>>a>>b>>c;
if(a==-1&&b==-1&&c==-1) break;
memset(visa,0,sizeof(visa));
memset(visb,0,sizeof(visb));
cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<w(a,b,c)<<endl;
}
return 0;
}
by lyq123bc @ 2024-07-04 20:47:14
record_link
by HJY2022 @ 2024-07-04 20:52:17
所以?
by xiaokang_suancai @ 2024-07-08 09:59:32
@lyq123bc 没事这个点我之前也TLE了,我后来看了一下输入输出的数据,发现他输入的是几百行相同的数据,你调用函数之前特判一下是否重复就行了