当前位置:网站首页>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;
}
边栏推荐
- S2b2b mall solution of intelligent supply chain in packaging industry: opening up a new ecosystem of e-commerce consumption
- Dependency injection 2 advantage lifecycle
- JNI uses asan to check memory leaks
- LM12丨Rolling Heikin Ashi二重K线滤波器
- Illegal behavior analysis 1
- Installing gradle
- Explain
- Take you hand in hand to build Eureka server with idea
- SAP memory parameter tuning process
- C method question 1
猜你喜欢

电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级

Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process

C cat and dog

SAP HR labor contract information 0016

Ora-01741 and ora-01704

C method question 1

Three questions TDM

ping报错:未知的名称或服务

Flash encryption process and implementation of esp32
![[stm32+esp8266 connects to Tencent cloud IOT development platform 3] stm32+esp8266-01s dynamically registers devices on Tencent cloud (at instruction mode) -- with source code](/img/55/ab50ead2564498cb214d98ac5b9c3d.jpg)
[stm32+esp8266 connects to Tencent cloud IOT development platform 3] stm32+esp8266-01s dynamically registers devices on Tencent cloud (at instruction mode) -- with source code
随机推荐
PCB wiring rules of PCI Express interface
UE4_ Ue5 panoramic camera
B_QuRT_User_Guide(38)
Understand TCP's three handshakes and four waves with love
8.31 Tencent interview
伸展树(一) - 图文解析与C语言实现
SAP HR labor contract information 0016
SQL database execution problems
二叉排序树【BST】——创建、查找、删除、输出
MySQL Architecture
The file format and extension of XLS do not match
B_QuRT_User_Guide(36)
How to change the formula picture in the paper directly into the formula in word
[stm32+esp8266 connect Tencent cloud IOT development platform 2] stm32+esp8266-01s connect Tencent cloud
包装行业智能供应链S2B2B商城解决方案:开辟电商消费新生态
ASP. Net query implementation
USB (XVI) 2022-04-28
JNI uses asan to check memory leaks
ping报错:未知的名称或服务
【7.4】25. Turn over the linked list in groups of K