C++14:听取TLE声一片

P1464 Function

递归不超时就怪了
by _C_ccx_N_ @ 2024-05-12 11:24:01


@[wangruize88](/user/947202) 记忆化搜索
by zhouzihang1 @ 2024-05-12 11:27:52


时间复杂度太高了
by markkkk @ 2024-05-12 12:43:38


记忆化: # 禁止抄袭,仅供借鉴 ```cpp #include<bits/stdc++.h> #define ll long long using namespace std; ll arr[100][100][100]; bool vis[100][100][100]; ll func(ll a,ll b,ll c){ if(a<=0 or b<=0 or c<=0) return 1; if(a>20 or b>20 or c>20) return func(20,20,20); if(vis[a][b][c]) return arr[a][b][c]; if(a<b and b<c) arr[a][b][c]=func(a,b,c-1)+func(a,b-1,c-1)-func(a,b-1,c); else arr[a][b][c]=func(a-1,b,c)+func(a-1,b-1,c)+func(a-1,b,c-1)-func(a-1,b-1,c-1); vis[a][b][c]=true; return arr[a][b][c]; } int main(){ ll a,b,c; while(true){ cin>>a>>b>>c; if(a==-1&&b==-1&&c==-1) break; printf("w(%ld, %ld, %ld) = %ld\n",a,b,c,func(a,b,c)); } return 0; } ```
by Vincent615 @ 2024-05-12 12:49:55


|