社区讨论
Sub#1全错,100分求调
P1464[PacNW 1999] Function参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @mhjdhclz
- 此快照首次捕获于
- 2025/11/04 00:46 4 个月前
- 此快照最后确认于
- 2025/11/04 00:46 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
unordered_map<string,long long> m;
int w(int a,long long b,long long c){
string s;
s='#'+to_string(a)+'#'+to_string(b)+'#'+to_string(c);
auto it=m.find(s);
if(it!=m.end()){
return it->second;
}
else{
if(a<=0||b<=0||c<=0){
long long ans=1;
string t='#'+to_string(a)+'#'+to_string(b)+'#'+to_string(c);
m[t]=ans;
return ans;
}else if(a>20||b>20||c>20){
long long ans=w(20,20,20);
string t='#'+to_string(a)+'#'+to_string(b)+'#'+to_string(c);
m[t]=ans;
return ans;
}else if(a<b&&b<c){
long long ans=w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c);
string t='#'+to_string(a)+'#'+to_string(b)+'#'+to_string(c);
m[t]=ans;
return ans;
}else{
long long ans=w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);
string t='#'+to_string(a)+'#'+to_string(b)+'#'+to_string(c);
m[t]=ans;
return ans;
}
}
}
int main(){
long long a,b,c;
while(a!=-1||b!=-1||c!=-1){
cin>>a>>b>>c;
if(a!=-1||b!=-1||c!=-1){
int ans=w(a,b,c);
printf("w(%d, %d, %d) = %d\n",a,b,c,ans);
}
}
return 0;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...