当前位置:网站首页>放苹果(暑假每日一题 13)
放苹果(暑假每日一题 13)
2022-08-02 11:08:00 【sweetheart7-7】
把 M M M 个同样的苹果放在 N N N 个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?
盘子相对顺序不同,例如 5 , 1 , 1 5,1,1 5,1,1 和 1 , 5 , 1 1,5,1 1,5,1 算作同一种分法。
输入格式
输入包含多组测试数据。
每组数据占一行,包含两个整数 M M M 和 N N N。
输出格式
每组数据,输出一行一个结果表示分法数量。
数据范围
1 ≤ M , N ≤ 10 1≤M,N≤10 1≤M,N≤10
输入样例:
7 3
输出样例:
8
#include<iostream>
using namespace std;
int m, n;
int dfs(int u, int sum, int last){
if(u == n)
return sum == 0;
int res = 0;
for(int i = last; i <= sum; i++)
res += dfs(u + 1, sum - i, i);
return res;
}
int main(){
while(cin >> m >> n)
cout << dfs(0, m, 0) << endl;
return 0;
}
边栏推荐
- ECCV22|PromptDet:无需手动标注,迈向开放词汇的目标检测
- LayaBox---TypeScript---三斜线指令
- 3 d laser slam: LeGO - LOAM - ground point extracting method and the analysis of the code
- C#/VB.NET to add more lines more columns image watermark into the Word document
- sqli-labs(less-11)
- 划分训练集,验证集,测试集
- Alibaba CTO Cheng Li: Alibaba Open Source History, Concept and Practice
- How to encapsulate the wx.request() request of WeChat applet
- 10份重磅报告 — 展望中国数字经济未来
- 图形处理单元(GPU)的演进
猜你喜欢
随机推荐
Shell编程案例
微信小程序---组件开发与使用
LayaBox---TypeScript---迭代器和生成器
Mysql transaction isolation level and MVCC (multi-version concurrency control)
SVN如何删除文件名包含空格的文件
详细总结SoC、DSP、MCU、GPU和FPGA等基础概念
leetcode: 200. 岛屿数量
QT笔记——在一个窗口上显示另外一个透明窗口
4年手工测试被应届生取代了,用血与泪的教训给xdm一个忠告,该学自动化了...
3 d laser slam: LeGO - LOAM - ground point extracting method and the analysis of the code
循环结构--while循环
LayaBox---TypeScript---Mixins
mysql清除binlog日志文件
Mysql环境变量的配置(详细图解)
Challenge LeetCode1000 questions in 365 days - Day 047 Design Circular Queue Circular Queue
从零开始Blazor Server(5)--权限验证
LayaBox---TypeScript---Symbols
LayaBox---TypeScript---Mixins
5G基础学习1、5G网络架构、网络接口及协议栈
MySQL百万数据优化总结 一