60分求助!!! #3 #7

P1464 Function

```cpp while(1){ cin>>a>>b>>c if(a==-1&&b==-1&&c==-1) break; ll ina=a,inb=b,inc=c; if(a>20||b>20||c>20){ a=20; b=20; c=20; } cout<<"w("<<ina<<", "<<inb<<", "<<inc<<")"<<" = "<<w(a,b,c)<<endl; } ``` 给一组hack ``` -1 10 20 ``` 正确答案:1 你的答案:1048576
by zhouzihang1 @ 2023-08-24 21:36:24


先判断有没有<=0的,在判断有没有>20的
by zhouzihang1 @ 2023-08-24 21:37:15


@[levy2011](/user/990838)
by zhouzihang1 @ 2023-08-24 21:38:08


@[zhouzihang1](/user/827018) 改完了,变成#1 #2 WA ```cpp #include<bits/stdc++.h> #define ll long long using namespace std; bool vis[21][21][21]; ll v[21][21][21]; ll 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); else if(vis[a][b][c]) return v[a][b][c]; else if(a<b&&b<c) v[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c); else v[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); vis[a][b][c]=true; return v[a][b][c]; } int main(){ ll a=0,b=0,c=0; memset(vis,false,sizeof(vis)); while(1){ cin>>a>>b>>c; if(a==-1&&b==-1&&c==-1) break; cout<<"w("<<a<<", "<<b<<", "<<c<<")"<<" = "<<w(a,b,c)<<endl; } return 0; } ``````
by levy3304 @ 2023-08-24 22:06:00


求指点
by levy3304 @ 2023-08-24 22:06:57


```cpp else if(vis[a][b][c]) return v[a][b][c]; ``` 改成 ```cpp else if(v[a][b][c]) return v[a][b][c]; ``` 试试?
by zhouzihang1 @ 2023-08-25 07:26:56


@[zhouzihang1](/user/827018) 还是#1 #2 WA
by levy3304 @ 2023-08-25 09:26:57


AC了,感谢大佬指点!
by levy3304 @ 2023-08-25 10:24:45


|