__Harry_Haiyun__ @ 2023-08-08 15:14:34
#include <bits/stdc++.h>
#define MOD 998244353
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define ui unsigned int
using namespace std;
const int maxn = 1e6+9;
int w(int a,int b,int 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)
return w(a,b,c - 1) + w(a,b - 1,c - 1) - w(a,b - 1,c);
return w(a - 1,b,c) + w(a - 1,b - 1,c) + w(a - 1,b,c - 1) - w(a - 1,b - 1,c - 1);
}
int main()
{
int a,b,c;
while (cin >> a >> b >> c)
{
if (a == -1 && b == -1 && c == -1) break;
printf("w(%d, %d, %d) = %d",a,b,c,w(a,b,c));
}
return 0;
}
by 2011FYCCCTA @ 2023-08-08 15:33:27
@Harry_Haiyun 都define了怎么不用ull?
by 2011FYCCCTA @ 2023-08-08 15:34:24
还有要记忆化
by __Harry_Haiyun__ @ 2023-08-08 19:13:21
不行,全TLE
by Li_wc0802 @ 2023-08-18 08:06:45
@__Harry_Haiyun__ 这么写就对
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int ans[25][25][25];
long long w(long long a,long long b,long long c)
{
if(a<=0||b<=0||c<=0)
return 1;
if(a>20||b>20||c>20)
a=b=c=21;
if(ans[a][b][c])
return ans[a][b][c];
if(a>20||b>20||c>20)
return ans[a][b][c]=w(20,20,20);
if(a<b&&b<c)
return ans[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
return ans[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);
}
int main()
{
while(1)
{
long long x,y,z;
cin>>x>>y>>z;
if(x==-1&&y==-1&&z==-1)break;
printf("w(%lld, %lld, %lld) = %d\n",x,y,z,w(x,y,z));
}
return 0;
}