当前位置:网站首页>[niuke.com] ky41 put apples
[niuke.com] ky41 put apples
2022-06-11 21:47:00 【When the flower does not wither】

Use dynamic programming to solve .
When m >= n when , Or there is at least one apple on each plate , Or at least one empty plate , therefore dp[ i ][ j ] = dp[ i ][ j - 1 ] + dp[ i - j ][ j ].
When m < n when , At least n - m A plate is empty , At most m There are apples on a plate , therefore dp[ i ][ j ] = dp[ i ][ i ].
The boundary conditions , When there is only one plate or no apples , There is only one way .
#include<iostream>
#include<cstdio>
using namespace std;
const int N = 10 + 10;
int dp[N][N];
int main(){
int m, n;
while(scanf("%d%d", &m, &n) != EOF){
for(int i = 0; i <= m; i++) dp[i][1] = 1;
for(int j = 0; j <= n; j++) dp[0][j] = 1;
for(int i = 1; i <= m; i++){
for(int j = 1; j <= n; j++){
if(j <= i) dp[i][j] = dp[i][j - 1] + dp[i - j][j];
else dp[i][j] = dp[i][i];
}
}
printf("%d\n", dp[m][n]);
}
return 0;
}
边栏推荐
- The shortcomings of the "big model" and the strengths of the "knowledge map"
- Leetcode-322- change exchange
- 高考结束,人生才刚刚开始,10年职场老鸟给的建议
- 相对完善的单例模式
- LabVIEW控制Arduino实现红外测距(进阶篇—6)
- 2021 Niuke multi school 5 double strings
- Redis basic data type (list)
- LabVIEW Arduino electronic weighing system (project Part-1)
- EndnoteX9簡介及基本教程使用說明
- R语言书籍学习03 《深入浅出R语言数据分析》-第八章 逻辑回归模型 第九章 聚类模型
猜你喜欢

Classes and objects (3)

Matlab: 文件夹锁定问题的解决

RPA+低代码为何是加速财务数字化转型之利器?

Leetcode-322- change exchange

In the future, cloud expansion technology is expected to be selected as a specialized, special and new enterprise in Shanghai

The shortcomings of the "big model" and the strengths of the "knowledge map"

「大模型」之所短,「知识图谱」之所长

Classes and objects (1)

继承的所有特征

R语言书籍学习03 《深入浅出R语言数据分析》-第十章 关联规则 第十一章 随机森林
随机推荐
行而不辍,未来可期|云扩科技入选上海市专精特新企业
C语言实现八种排序 - 归并排序
Redis basic data type (hash)
Parker plunger pump pv180r1k1t1nmmc
Chain storage structure of linear table
Matlab: 文件夹锁定问题的解决
动态内存管理(1)
How to import workflows provided on SAP API hub to sap BTP
String copy function
EndnoteX9简介及基本教程使用说明
如何查看win系统的安装日期
网络连接正常但百度网页打不开显示无法访问此网站解决方案
RPA+低代码助推品牌电商启新创变、重启增长
LeetCode-76-最小覆盖子串
Introduction à endnotex9 et instructions pour les tutoriels de base
The same efficiency tool for leading enterprises to promote smart finance. Let's have a quick look?
All features of polymorphism
Redis basic data type (set)
LeetCode-110-平衡二叉树
建造者模式