会飞的禽兽 @ 2018-11-29 17:37:03
using namespace std; long long ans[30][30][30]={0,0,0}; int w(int a,int b,int c) { //cout<<"w(a,b,c)="<<a<<" "<<b<<" "<<c<<endl; if (a<=0||b<=0||c<=0) return 1; if (ans[a][b][c]!=0) return ans[a][b][c]; if (a<b&&b<c) { ans[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)+w(a,b-1,c); return ans[a][b][c]; } ans[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); return ans[a][b][c]; }
int main() { long long a,b,c; memset(ans,0,sizeof(ans)); while (cin>>a>>b>>c) { if (a==-1&&b==-1&&c==-1) break; printf("w(%lld, %lld, %lld) = ",a,b,c); if (a>20||b>20||c>20) a=b=c=20; int aaa=w(a,b,c); printf("%d\n",aaa); } return 0; }
by Victorique_De_Blois @ 2018-11-29 17:39:11
by NaCly_Fish @ 2018-11-29 17:41:20
它让你递归你就真递归啊
by NaCly_Fish @ 2018-11-29 17:42:32
@NaCly_Fish 抱歉看错了,还是用了记忆化的
by 会飞的禽兽 @ 2018-11-29 17:42:51
@NaCly_Fish 我用记忆化了呀。。
by sss7020 @ 2018-11-29 17:50:41
@会飞的禽兽 希望更丰富的展现?使用Markdown 请注意格式问题(输出的w括号里有空格)
by 会飞的禽兽 @ 2018-11-29 17:54:02
@Jack_killer 不。。。不会用呀。。。
by 会飞的禽兽 @ 2018-11-29 17:54:14
@陈博文1412 加空格了
by ⚡小林孑⚡ @ 2018-11-29 17:54:16
评测记录
by ⚡小林孑⚡ @ 2018-11-29 17:56:34
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long ans[30][30][30]={0,0,0};
int w(int a,int b,int c)
{ //cout<<"w(a,b,c)="<<a<<" "<<b<<" "<<c<<endl;
if (a<=0||b<=0||c<=0) return 1;
if (ans[a][b][c]!=0) return ans[a][b][c];
if (a<b&&b<c) {
ans[a][b][c]=w(a,b,c-1)+w(a,b-1,c-1)+w(a,b-1,c);
return ans[a][b][c]; } ans[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); return ans[a][b][c];
}
int main() {
long long a,b,c;
memset(ans,0,sizeof(ans));
while (cin>>a>>b>>c) {
if (a==-1&&b==-1&&c==-1) break;
printf("w(%lld, %lld, %lld) = ",a,b,c);
if (a>20||b>20||c>20) a=b=c=20;
int aaa=w(a,b,c); printf("%d\n",aaa);} return 0; }
by ⚡小林孑⚡ @ 2018-11-29 18:01:32
@会飞的禽兽 函数开long long ans数组开小了