2 条题解
-
0马睿 (2024sng28) LV 10 @ 2025-1-30 19:22:22
@曾致瑜呵呵
#include<bits/stdc++.h> using namespace std; const int N=1e5+5,INF=0x3f3f3f3f; typedef long long LL; int n,m; int f(int n,int m){ if(n<1||m<1)return 0; else if(n==1||m==1)return 1; else if(n<m)return f(n,n); else if(n==m)return f(n,m-1)+1; else return f(n,m-1)+f(n-m,m); } int main() { cin>>n; cout<<f(n,n); return 0; }
-
02023-1-26 17:56:15@
这道题除了我以外居然还没有人作对,那我来发一个题解扒
注意本题是求值问题,而非求最优解问题,不需要逐个输出各种情况,仅需输出最优值即可
算法分析
所以可以得出如下函数
例如:对于来说 计算可得
代码
#include<iostream> using namespace std; int hf(int x,int y) { if(x==1||y==1) { return 1; } else if (x<y) { return hf(x,x); } else if(x==y) { return hf(x,x-1)+1; } else { return hf(x,y-1)+hf(x-y,y); } } int main() { int n; cin>>n; cout<<hf(n,n); return 0; }
- 1
信息
- ID
- 1491
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 8
- 已通过
- 5
- 上传者