当前位置:网站首页>P2404 splitting of natural numbers
P2404 splitting of natural numbers
2022-07-24 21:33:00 【A little Yu】
Copy Markdown an
Title Description
Any one is greater than 11 The natural number of nn, It can be divided into several smaller than nn The sum of the natural numbers of . Now I'll give you a natural number nn, Ask you to find out nn Split into some numbers and . The numbers in each split sequence are sorted from small to large . Then you need to output these sequences , Among them, the sequence with small dictionary order needs to be output first .
Input format
Input : Natural number to be split nn.
Output format
Output : The addition formula of some numbers .
I/o sample
Input #1 Copy
7
Output #1 Copy
1+1+1+1+1+1+1 1+1+1+1+1+2 1+1+1+1+3 1+1+1+2+2 1+1+1+4 1+1+2+3 1+1+5 1+2+2+2 1+2+4 1+3+3 1+6 2+2+3 2+5 3+4
explain / Tips
Data assurance ,1<=n<=8
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
int a[10001]= {1};
int n;
void print(int t)
{
for(int i=1; i<=t-1; i++)
cout<<a[i]<<"+";
cout<<a[t]<<endl;
}
void dfs(int s,int t)
{
for(int i=a[t-1]; i<=s; i++)// Greater than or equal to the previous digit
{
if(i<n)
{
a[t]=i;
s-=i;
if(s==0) print(t);
else dfs(s,t+1);
s+=i;
}
}
}
int main()
{
cin>>n;
dfs(n,1);
return 0;
}
边栏推荐
- [basic data mining technology] exploratory data analysis
- With this PDF, I successfully got offers from ant, jd.com, Xiaomi, Tencent and other major manufacturers
- Hilditch refinement (implementation I)
- How to gracefully realize regular backup of MySQL database (glory Collection Edition)
- Five digital transformation strategies of B2B Enterprises
- Summary of yarn Explorer
- 支付宝上股票开户安全吗
- Overview and installation of scientific computing toolkit scipyscipy
- One bite of Stream(7)
- What are intelligent investment advisory products?
猜你喜欢

String matching (Huawei)

Mathpix formula extractor

Information System Project Manager - Chapter 10 project communication management and project stakeholder management

Drive subsystem development

Solution: 2003 cant connect to MySQL server on * * * * and use near 'identified by' * * * * 'with grant option' at

Mysql database query is so slow. Besides index, what else can it do?

Baidu interview question - judge whether a positive integer is to the power of K of 2

With this PDF, I successfully got offers from ant, jd.com, Xiaomi, Tencent and other major manufacturers
![[feature selection] several methods of feature selection](/img/ee/2f5224f97ac3090a535c9c74bc898f.png)
[feature selection] several methods of feature selection

Nested printing in CAD web pages
随机推荐
Using gcc to avoid stack smash attack
[jzof] 06 print linked list from end to end
Classical review: understanding the "knowledge consistency" of neural networks (ICLR 2020)
MySQL - multi table query - seven join implementations, set operations, multi table query exercises
Rce (no echo)
Intranet penetration learning (I) introduction to Intranet
Put apples
Summary of yarn Explorer
Experience of using dump file to reverse locate crash location
Hilditch refinement (implementation I)
How to gracefully realize regular backup of MySQL database (glory Collection Edition)
Mysql database commands
[untitled]
Intel internship mentor layout problem 1
Overloaded & lt; for cv:: point;, But VS2010 cannot find it
驱动子系统开发
Static & dynamic & file address book
Go language pack management
250 million, Banan District perception system data collection, background analysis, Xueliang engineering network and operation and maintenance service project: Chinatelecom won the bid
Es+redis+mysql, the high availability architecture design is awesome! (supreme Collection Edition)