levy3304 @ 2023-08-24 21:31:09
#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;
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;
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;
}
return 0;
}
by zhouzihang1 @ 2023-08-24 21:36:24
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:37:15
先判断有没有<=0的,在判断有没有>20的
by zhouzihang1 @ 2023-08-24 21:38:08
@levy2011
by levy3304 @ 2023-08-24 22:06:00
@zhouzihang1 改完了,变成#1 #2 WA
#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:57
求指点
by zhouzihang1 @ 2023-08-25 07:26:56
else if(vis[a][b][c]) return v[a][b][c];
改成
else if(v[a][b][c]) return v[a][b][c];
试试?
by levy3304 @ 2023-08-25 09:26:57
@zhouzihang1 还是#1 #2 WA
by levy3304 @ 2023-08-25 10:24:45
AC了,感谢大佬指点!