Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
99869 | 王为治 | 拆分自然数 | C++ | 通过 | 100 | 248 MS | 252 KB | 646 | 2023-08-24 09:43:12 |
#include <bits/stdc++.h> using namespace std; int ans[114]; int n; int cnt = 0; void dfs(int x, int y) { if(x==1) { ans[y]=1; cout << n << "=" << ans[1]; cnt++; for(int k = 2; k <= y; k++) { cout << '+' << ans[k]; } cout << endl; } else { for(int j = ans[y-1]; j <= x/2; j++) { ans[y] = j; dfs(x-j,y+1); } ans[y]=x; cout << n << "=" << ans[1]; cnt++; for(int k = 2; k <= y; k++) { cout << '+' << ans[k]; } cout << endl; } } signed main() { cin >> n; for(int i = 1; i <= n/2; i++) { ans[1]=i; dfs(n-i,2); } cout << cnt << endl; return 0; }