xiaokang_suancai @ 2024-07-08 08:37:55
子任务测试点2 TLE的看过来: 这个测试点的输入内容是几百行重复的数值,加个特判判断输入的内容是否和前面一样,要是一样直接输出就行了(别问我是怎么知道的……)
by wheat__ @ 2024-07-08 08:38:25
orz
by louie2011 @ 2024-07-25 19:48:06
记忆化..
by xiaokang_suancai @ 2024-08-03 12:58:28
@louie2011 我就是用记忆化写的,然后那个点T了
by louie2011 @ 2024-08-03 16:52:34
@xiaokang_suancai 但是我没有t,我的代码wa了,20分
by xiaokang_suancai @ 2024-08-03 18:29:07
@louie2011 额要不你发一下代码我瞧瞧?虽然我也是蒟蒻
by louie2011 @ 2024-08-04 09:38:15
@xiaokang_suancai
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
int f[25][25][25];
int dfs(int x,int y,int z)
{
if(x<=0 || y<=0 || z<=0)
{
return 1;
}
if(x>20 || y>20 || z>20)
{
return dfs(20,20,20);
}
if(f[x][y][z])
{
return f[x][y][z];
}
if(x<y && y<z)
{
f[x][y][z]=dfs(x,y,z-1)+dfs(x,y-1,z-1)-dfs(x,y-1,z);
}
else
{
f[x][y][z]=dfs(x-1,y,z)+dfs(x-1,y-1,z)+dfs(x-1,y,z-1)-dfs(x-1,y-1,z-1);
}
return f[x][y][z];
}
int a,b,c;
signed main()
{
while(1)
{
cin>>a>>b>>c;
if(a==-1 && b==-1 && c==-1)
{
break;
}
cout<<"w("<<a<<", "<<b<<", "<<c<<") = "<<dfs(max((long long)0,min((long long)20,a)),max((long long)0,min((long long)20,b)),max((long long)0,min((long long)20,c)))<<endl;;
}
return 0;
}
by xiaokang_suancai @ 2024-08-04 10:56:32
@louie2011 你开 long long 试试?
by xiaokang_suancai @ 2024-08-04 10:58:56
@xiaokang_suancai 哦,当我没说
by xiaokang_suancai @ 2024-08-04 11:05:03
@louie2011 因为这是多组数据的题目,所以记忆化的答案每次循环都要刷新,在 while 里加上 memset(f,0,sizeof(f))
by xiaokang_suancai @ 2024-08-04 11:07:14
@louie2011 cout 不用写这么麻烦,直接dfs(a,b,c) 就行了