8 条题解
-
8
递归,好像是多项式,对吗?代码应该没问题。
#include<bits/stdc++.h> using namespace std; long long w(long long a,long long b,long long c){ if (a <= 0 || b <= 0 || c <= 0){ return 1; } else if (a > 10 || b > 10 || c > 10){ return w(10,10,10); } else if (a < b && b < c){ return w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c); } else{ return w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1); } } int main() { long long a,b,c,k; cin >> a >> b >> c; k = w(a,b,c); cout << "w(" << a << ',' << b << ',' << c <<")=" << k; return 0; }
-
6
yasuo告诉您,递归考察0%,运算符考察1%,复制能力考查99%👀️
#include <iostream> double w(long long a,long long b,long long c){ if(a<=0||b<=0||c<=0) return 1; if(a>10||b>10||c>10) return w(10,10,10); if(a<b&&b<c) return w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c); return w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1);} int main(){ long long a,b,c;std::cin>>a>>b>>c; std::cout<<"w("<<a<<","<<b<<","<<c<<")="<<w(a,b,c);return 0;}
-
5
解析
根据题目写出递归表达式和终止条件。需要注意数据范围会爆int,使用long long就好了
题解
#include <iostream> using namespace std; long long a, b, c; long long w(long long a, long long b, long long c) { if (a <= 0 || b <= 0 || c <= 0) return 1; else if (a > 10 || b > 10 || c > 10) return w(10, 10, 10); else if (a < b && b < c) return w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c); else return w(a - 1, b, c) + w(a - 1, b - 1, c) + w(a - 1, b, c - 1) - w(a - 1, b - 1, c - 1); } int main() { cin >> a >> b >> c; cout << "w(" << a << "," << b << "," << c << ")=" << w(a, b, c) << endl; }
-
3
#include <bits/stdc++.h> #define ll long long using namespace std; ll w(ll a, ll b, ll c) { if (a <= 0 || b <= 0 || c <= 0) return 1; else if (a > 10 || b > 10 || c > 10) return w(10, 10, 10); else if (a < b && b < c) return w(a, b, c - 1) + w(a, b - 1, c - 1) - w(a, b - 1, c); else return w(a - 1, b, c) + w(a - 1, b - 1, c) + w(a - 1, b, c - 1) - w(a - 1, b - 1, c - 1); } int main() { ll a, b, c; cin >> a >> b >> c; cout << "w(" << a << "," << b << "," << c << ")=" << w(a, b, c); }
-
1
#include using namespace std; int w(int a,int b,int c) { if(a<=0 || b<=0 ||c<=0) { return 1; } if(a>10 || b>10 || c>10) { return w(10,10,10); } if(a<b && b<c) { return w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c); } else { return w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1); } } int x,y,z; int main() { cin>>x>>y>>z; int ans=w(x,y,z); cout<<"w("<<x<<","<<y<<","<<z<<")="<<ans; }
90?
long long!!
#include <iostream> using namespace std; int w(int a,int b,int c) { if(a<=0 || b<=0 ||c<=0) { return 1; } if(a>10 || b>10 || c>10) { return w(10,10,10); } if(a<b && b<c) { return w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c); } else { return w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1); } } long long x,y,z; int main() { cin>>x>>y>>z; int ans=w(x,y,z); cout<<"w("<<x<<","<<y<<","<<z<<")="<<ans; }
100!!
-
0
#include<bits/stdc++.h> using namespace std; long long w(long long a,long long b,long long c) { if(a<=0||b<=0||c<=0) return 1; else if(a>b&&b>c) return w(a,b,c-1)+w(a,b-1,c-1)-w(a,b-1,c); else return w(a-1,b,c)+w(a-1,b-1,c)+w(a-1,b,c-1)-w(a-1,b-1,c-1); } int main() { long long a,b,c; cin>>a>>b>>c; if (a<=0||b<=0||c<=0)printf("w(%lld,%lld,%lld)=1",a,b,c); else if(a>10||b>10||c>10) printf("w(%lld,%lld,%lld)=%lld",a,b,c,w(10,10,10)); else printf("w(%lld,%lld,%lld)=%lld",a,b,c,w(a,b,c)); return 0; }
-
0
这题没啥难度,递归式和边界条件全在题目里了,注意一下输出格式就行
#include <iostream> using namespace std; long long w(long long a,long long b,long long c) { if(a <= 0 || b <= 0 || c <= 0) return 1; else if(a > 10 || b > 10 || c > 10) return w(10,10,10); else if(a < b && b < c) return w(a,b,c - 1) + w(a,b - 1,c - 1) - w(a,b - 1,c); else return w(a - 1,b,c) + w(a - 1,b - 1,c) + w(a - 1,b,c - 1) - w(a - 1,b - 1,c - 1); } int main() { long long a,b,c; cin >> a >> b >> c; cout << "w(" << a << ',' << b << ',' << c << ")=" << w(a,b,c); return 0; }
-
-3
- 1
信息
- ID
- 309
- 时间
- 2000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 1677
- 已通过
- 512
- 上传者