0分求助大神帮助

P1464 Function

me too ```cpp #include<bits/stdc++.h> using namespace std; long long a[10001],b[10001],c[10001],k=1; long long w(long long x,long long y,long long z) { if(x<=0 || y<=0 || z<=0) { return 1; } else if(x>20 || y>20 || z>20) { return w(20,20,20); } else if(x<y && y<z) { return w(x,y,z-1)+w(x,y-1,z-1)-w(x,y-1,z); } else { return w(x-1,y,z)+w(x-1,y-1,z)+w(x-1,y,z-1)-w(x-1,y-1,z-1); } } int main() { while(1) { cin>>a[k]>>b[k]>>c[k]; if(a[k]==-1 && b[k]==-1 && c[k]==-1) { break; } k++; } k--; for(int i=1;i<=k;i++) { cout<<"w("<<a[i]<<","<<b[i]<<","<<c[i]<<") = "<<w(a[i],b[i],c[i])<<endl; } } ```
by Wyz110628 @ 2023-10-28 10:04:45


```cpp #include<bits/stdc++.h> using namespace std; long long f[200][200][200]; #define main mian long long dfs(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){ return 1048576; } if(f[a][b][c]!=0){ return f[a][b][c]; } if(a<b&&b<c){ f[a][b][c]=dfs(a,b,c-1)+dfs(a,b-1,c-1)-dfs(a,b-1,c); return f[a][b][c]; } f[a][b][c]=dfs(a-1,b,c)+dfs(a-1,b-1,c)+dfs(a-1,b,c-1)-dfs(a-1,b-1,c-1); return f[a][b][c]; } int main(){ while(true){ long long a,b,c; cin>>a>>b>>c; if(a==b&&b==c&&c==-1){ break; } printf("w(%lld, %lld, %lld) = %lld\n",a,b,c,dfs(a,b,c)); } return 0; } ``` 仅供参考,直接复制不得分
by zero_egg @ 2023-10-28 10:09:29


|