poj 1664放苹果(递归)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 37377 | Accepted: 23016 |
Description
Input
Output
Sample Input
1
7 3
Sample Output
8
对于m个苹果,n个盘子f(m,n):
如果m<n,那么就跟m个盘子,m个苹果是一样的f(m,m)。
如果m>n,那么有两种情况:一种有空盘子的情况,一种没有空盘子的情况,两种情况不重叠且加一起一定为情况总数。
第一种情况:m个苹果放在n-1个盘子里,因为至少有1个空盘子,即f(m,n-1)
第二种情况:每个盘子都至少有一个苹果,m-n个苹果再放到n个盘子里,即f(m-n,n)。
由上面两种情况得到递归式f(m,n)=f(m,n-1)+f(m-n,n)。
#include<iostream>
#include<cstring>
using namespace std;
const int maxm=;
int m[maxm],n[maxm],k[maxm];//m是苹果树,n是盘子数
int putApple(int m,int n)
{
if(m==||n==)
return ;
else if(n>m)
return putApple(m,m);
else
return putApple(m,n-)+putApple(m-n,n);
}
int main()
{
memset(k,,sizeof(k));
int t;
cin>>t;
for(int i=;i<=t;i++)//一次性输入
{
cin>>m[i]>>n[i];
}
for(int i=;i<=t;i++)//一次性输出
{
k[i]=putApple(m[i],n[i]);
cout<<k[i]<<endl;
}
return ;
}
poj 1664放苹果(递归)的更多相关文章
- poj 1664 放苹果 递归
题目链接: http://poj.org/problem?id=1664 题目描述: 有n个苹果,m个盒子,盒子和苹果都没有顺序,盒子可以为空,问:有多少种放置方式? 解题思路: 当前有n个苹果,m个 ...
- poj 1664 放苹果(递推)
题目链接:http://poj.org/problem? id=1664 放苹果 Time Limit: 1000MS Memory Limit: 10000K Total Submissions ...
- POJ 1664 放苹果 (递推思想)
原题链接:http://poj.org/problem?id=1664 思路:苹果m个,盘子n个.假设 f ( m , n ) 代表 m 个苹果,n个盘子有 f ( m , n ) 种放法. 根据 n ...
- POJ 1664 放苹果
放苹果 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24985 Accepted: 15908 Description ...
- poj 1664 放苹果(dfs)
放苹果 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30284 Accepted: 19098 Description ...
- poj 1664 放苹果 (划分数)
题意:中文题目,不解释... 题解: 第一种方法是暴力深搜:枚举盘子1~n放苹果数量的所有情况,不需要剪枝:将每次枚举的情况,即每个盘的苹果数量,以字典序排序,然后存进set里 以此去重像" ...
- POJ 1664 放苹果(递归或DP)
一.Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. Input 第一行是测试数据的数目t ...
- poj 1664 放苹果,递归(深度优先搜索)
#include "stdio.h" int DFS(int n,int m); int main() { int T; int n,m; int s; scanf("% ...
- poj 1664放苹果(转载,不详细,勿点)(递归)
题目和别人的解析传送门 我的代码 #include<bits/stdc++.h> using namespace std; int f(int m,int n) { ) ; ||m==) ...
随机推荐
- XMPP协议相关基础概念(Strophe学习笔记)
相关资料: XMPP官网http://xmpp.org/xmpp-software/libraries/ nginx的转发配置http://mineral.iteye.com/blog/448260 ...
- 正则表达式计算 origin = "1 - 2 * ( ( 60 - 30 + ( -40.0 / 5 ) * ( 9 - 2 * 5 / 3 + 7 / 3 * 99 / 4 * 2998 + 10 * 568 / 14 )) - ( - 4 * 3 ) / ( 16 - 3 * 2))"
#!/usr/bin/env python import re def f1(arg): return 1 origin = "1 - 2 * ( ( 60 - 30 + ( -40.0 / ...
- 返回键的复写onBackPressed()介绍
本篇文章是对Android中返回键的复写onBackPressed()进行了详细的分析介绍,需要的朋友参考下 在android开发中,当不满足触发条件就按返回键的时候,就要对此进行检测.尤其是当前Ac ...
- 获取百度搜索结果的真实url以及摘要和时间
利用requests库和bs4实现,demo如下: #coding:utf- import requests from bs4 import BeautifulSoup import bs4 impo ...
- Windows版本Apache+php的Xhprof应用
[知识] {Apache} Apache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一. {PHP} ...
- No bean class specified on bean definition 解决方案
调试Spring项目出现No bean class specified on bean definition异常 但是控制台并没有给出其他相关信息了 这个时候可以在AbstractBeanDefini ...
- Ros指令集
rospack = ros+pack(age) : provides information related to ROS packages rosstack = ros+stack : provid ...
- .NET回归 HTML----表单元素(1)和一些常用的标记
表单就是-----用于搜集不同类型的用户输入. 表单元素指的是不同类型的 input 元素.复选框.单选按钮.提交按钮等等. 首先将表单元素分为三个类型.文本类,按钮类,选择类. 表单可以嵌套在表中, ...
- SQl Server Tsql基本编程 ,循环语句 ,存储过程
一些比较重要但是不一定经常用的 句子 Tsql定义变量 declare @a int : 定义的变量前面必须用@,数据类型是SQL里的数据类型,执行的时候要把需要的有关联的代码一起执行,单独执行一条 ...
- OpenGL超级宝典完整源码(第五版)
链接:https://pan.baidu.com/s/1dGQkk4T 密码:wu44 Visual Studio 2017配置OpenGL https://blog.csdn.net/qiangbi ...