当前位置:网站首页>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;
}
边栏推荐
- 平衡二叉樹【AVL樹】——插入、删除
- 2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion
- 生鲜行业数字化采购管理系统:助力生鲜企业解决采购难题,全程线上化采购执行
- Progress broadcast | all 29 shield machines of Guangzhou Metro Line 7 have been launched
- Happy gathering time
- 城联优品作为新力量初注入,相关上市公司股价应声上涨150%
- The efficient s2b2c e-commerce system helps electronic material enterprises improve their adaptability in this way
- Open source hardware small project: anxinco esp-c3f control ws2812
- Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
- B_QuRT_User_Guide(36)
猜你喜欢

进度播报|广州地铁七号线全线29台盾构机全部完成始发

平衡二叉樹【AVL樹】——插入、删除

SAP HR奖罚信息导出

Solution of intelligent supply chain collaboration platform in electronic equipment industry: solve inefficiency and enable digital upgrading of industry

SAP HR 家庭成员信息

2022 Season 6 perfect children's model Shaanxi finals came to a successful conclusion

B / Qurt Utilisateur Guide (36)

As a new force, chenglian premium products was initially injected, and the shares of relevant listed companies rose 150% in response

Markdown

电子设备行业智能供应链协同平台解决方案:解决低效, 赋能产业数字化升级
随机推荐
Summary of common methods of object class (September 14, 2020)
【实验分享】通过Console口登录到Cisco设备
Extended tree (I) - graphic analysis and C language implementation
PCB wiring rules of PCI Express interface
SAP memory parameter tuning process
【路径规划】使用垂距限值法与贝塞尔优化A星路径
Ora-02437 failed to verify the primary key violation
UE4_ Use of ue5 blueprint command node (turn on / off screen response log publish full screen display)
ESP at installation esp8266 and esp32 versions
Mobile heterogeneous computing technology - GPU OpenCL programming (basic)
UE4_ Ue5 panoramic camera
2022第六季完美童模陕西总决赛圆满落幕
家用电器行业渠道商协同系统解决方案:助力家电企业快速实现渠道互联网化
C simple question one
Interface
进度播报|广州地铁七号线全线29台盾构机全部完成始发
Anxin can internally test offline voice module vb-01 to communicate with esp-c3-12f
Digital procurement management system for fresh food industry: help fresh food enterprises solve procurement problems and implement online procurement throughout the process
Given an array, such as [7864, 284, 347, 7732, 8498], now you need to splice the numbers in the array to return the "largest possible number."
Idea automatically generates serialVersionUID