当前位置:网站首页>C - minute number V3
C - minute number V3
2022-07-07 23:39:00 【Yuesi】
recursive
C - Minute number V3
# subject
take n Divide into m More than 0 The sum of different numbers of ,1 2 Same as 2 1 Treat as the same division .
Output all schemes in dictionary order . Data guarantee existence solution , That is, there will be no 1+2+…m > n The situation of
## Input
2 Number n,m(1 <= m <= 10,1 <= n <= 50 ).
(1+2+…m > n)
## Output
In dictionary order , Output all schemes . Between the numbers , Divide... With spaces .
## The sample input :
13 3
## Sample output :
1 2 10
1 3 9
1 4 8
1 5 7
2 3 8
2 4 7
2 5 6
3 4 6
#include<bits/stdc++.h>
using namespace std;
int m,n;
int num[100]={
0};
void dfs(int u,int x)
{
if(u>m+1||x<0)
// Not in line with the question
// It's ready m I didn't get the sum of my share n and m Not enough and more than n
{
return;// Go back to the previous step
}
if(u==m+1&&x==0)
// In line with the meaning of the topic , Output arrangement , And return to the previous step
{
for(int i=1;i<m;i++)
{
cout<<num[i]<<" ";
// Separate with a space
}
cout<<num[m]<<endl;
return;
}
for(int i=num[u-1]+1;i<=x;i++)
{
num[u]=i;// Save each value
dfs(u+1,x-i);
// Must be written as x-i
// It can't be written as x( Add in the previous step x=x-i;) Wrong
}
}
int main(){
scanf("%d%d",&n,&m);
// take n Divide into m Share
dfs(1,n);// From the first , The remaining number is n
return 0;
}
边栏推荐
- redis缓存工具类,值得拥有~
- C method question 1
- Take you hand in hand to build Eureka server with idea
- Ora-01741 and ora-01704
- 二叉排序树【BST】——创建、查找、删除、输出
- Design and implementation of spark offline development framework
- Come on, brother
- New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
- Anxin vb01 offline voice module access intelligent curtain guidance
- HDU 4747 mex "recommended collection"
猜你喜欢
【路径规划】使用垂距限值法与贝塞尔优化A星路径
ASP. Net core middleware request processing pipeline
Open source hardware small project: anxinco esp-c3f control ws2812
Deep understanding of MySQL lock and transaction isolation level
Idea automatically generates serialVersionUID
平衡二叉樹【AVL樹】——插入、删除
New potential energy of industrial integration, Xiamen station of city chain technology digital summit successfully held
平衡二叉树【AVL树】——插入、删除
Svn relocation
Extended tree (I) - graphic analysis and C language implementation
随机推荐
0-1背包问题
产业共融新势能,城链科技数字峰会厦门站成功举办
windows设置redis开启自动启动
Class C design questions
2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
List. How to achieve ascending and descending sort() 2020.8.6
SAP HR labor contract information 0016
JNI uses asan to check memory leaks
Come on, brother
高效的S2B2C电商系统,是这样帮助电子材料企业提升应变能力的
Three questions TDM
Flash encryption process and implementation of esp32
Live server usage
C simple question one
[experiment sharing] log in to Cisco devices through the console port
SAP HR奖罚信息导出
USB (XVIII) 2022-04-17
SAP HR 劳动合同信息 0016
Spark 离线开发框架设计与实现
First week of July