2 条题解
-
0
#include <queue> #include <math.h> #include <stack> #include <stdio.h> #include <iostream> #include <vector> #include <iomanip> #include <string.h> #include <algorithm> using namespace std; #define LL long long const int N = 1e6 + 10; const int INF = 0x3f3f3f3f; int ans[N]; int n, total; void pr(int d){ total+=1; cout<<n<<"="; for(int i=1; i<=d-1; i++)cout<<ans[i]<<"+"; cout<<ans[d]<<endl; } void dfs(int dep, int rest){ if(rest==0){ if(dep>2){ pr(dep-1); return; } } for(int i=ans[dep-1]; i<=rest; i++){ ans[dep]=i; dfs(dep+1, rest-i); } } int main() { cin>>n; ans[0]=1; dfs(1, n); cout<<"total="<<total; return 0; }
信息
- ID
- 1242
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- 递交数
- 304
- 已通过
- 137
- 上传者