敲烂警钟

P1464 Function

orz
by wheat__ @ 2024-07-08 08:38:25


记忆化..
by louie2011 @ 2024-07-25 19:48:06


@[louie2011](/user/941801) 我就是用记忆化写的,然后那个点T了
by xiaokang_suancai @ 2024-08-03 12:58:28


@[xiaokang_suancai](/user/1169788) 但是我没有t,我的代码wa了,20分
by louie2011 @ 2024-08-03 16:52:34


@[louie2011](/user/941801) 额要不你发一下代码我瞧瞧?~~虽然我也是蒟蒻~~
by xiaokang_suancai @ 2024-08-03 18:29:07


@[xiaokang_suancai](/user/1169788) ```cpp #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 louie2011 @ 2024-08-04 09:38:15


@[louie2011](/user/941801) 你开 long long 试试?
by xiaokang_suancai @ 2024-08-04 10:56:32


@[xiaokang_suancai](/user/1169788) 哦,当我没说
by xiaokang_suancai @ 2024-08-04 10:58:56


@[louie2011](/user/941801) 因为这是多组数据的题目,所以记忆化的答案每次循环都要刷新,在 while 里加上 memset(f,0,sizeof(f))
by xiaokang_suancai @ 2024-08-04 11:05:03


@[louie2011](/user/941801) cout 不用写这么麻烦,直接dfs(a,b,c) 就行了
by xiaokang_suancai @ 2024-08-04 11:07:14


| 下一页