当前位置:网站首页>放苹果(暑假每日一题 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;
}
边栏推荐
猜你喜欢
深度学习100例 —— 卷积神经网络(CNN)实现mnist手写数字识别
How to choose a truly "easy-to-use, high-performance" remote control software
博云入选Gartner中国DevOps代表厂商
数字化转型中的低代码
Mysql transaction isolation level and MVCC (multi-version concurrency control)
开箱即用-使用异步加载布局来优化页面启动速度的几种方案
ASP.NET Core 6框架揭秘实例演示[31]:路由&quot;高阶&quot;用法
企业级数据治理工作怎么开展?Datahub这样做
Alibaba CTO Cheng Li: Alibaba Open Source History, Concept and Practice
多大数量级会出现哈希碰撞
随机推荐
多大数量级会出现哈希碰撞
小程序插件的生态丰富,加速开发建设效率
学习笔记-支付宝支付
LayaBox---TypeScript---Module
LayaBox---TypeScript---模块
21 Days Learning Challenge - Day 1 Punch (Screen Density)
Shell编程之条件语句
sva 断言资料
Outsourced Student Management System Architecture Documentation
bgp与mpls综合实验
从幻核疑似裁撤看如何保证NFT的安全
软件测试岗位巨坑?阿里在职7年测试人告诉你千万别上当
阿里云数据存储生态计划发布,助力伙伴数据创新
X86函数调用模型分析
19、商品微服务-srv层实现
只问耕耘,不问收获,其实收获却在耕耘中
LayaBox---TypeScript---命名空间和模块
当POC遇见RPA:RPA项目顺利实施的关键
Why use BGP?
LayaBox---TypeScript---Namespaces and modules