poj--1664--放苹果(递归好体)
Time Limit: 1000MS | Memory Limit: 10000KB | 64bit IO Format: %I64d & %I64u |
Description
Input
Output
Sample Input
- 1
- 7 3
Sample Output
- 8
Source
(1)只有一个盘子的时候就只有把所有的苹果都放在一个盘子里,没有苹果的时候也没办法放
(2)盘子数多于苹果数时,最多放在m个盘子中dfs(m,m)
(3)m个苹果可以放在n-1个盘子中,当然,递归的时候也是可以做到放在n-2个盘子中,而如果说放在n个盘子中的话每个盘子至少有一个,也就是dfs(m-n,n);
- #include<stdio.h>
- #include<string.h>
- #include<algorithm>
- using namespace std;
- int dfs(int m,int n)
- {
- if(m==0||n==1)
- return 1;
- if(n>m)
- dfs(m,m);
- else
- return dfs(m,n-1)+dfs(m-n,n);
- }
- int main()
- {
- int t;
- scanf("%d",&t);
- while(t--)
- {
- int n,m;
- scanf("%d%d",&m,&n);
- printf("%d\n",dfs(m,n));
- }
- return 0;
- }
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放苹果(递归)
放苹果 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 37377 Accepted: 23016 Description ...
- 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==) ...
随机推荐
- ★Java语法(六)——————————分支语句
1. if 语句 格式用法: if(布尔表达式) { 语句: } 2. if……else 语句 格式用法: if(表达式) { 语句1: } else { 语句2: } 3.if……else i ...
- Shiro Shiro Web Support and EnvironmentLoaderListener
Shiro Shiro Web Support 主要参考: http://shiro.apache.org/web.html 还有涛哥的 作为资源控制访问的事情,主要使用在网络后台方面,所以了解了本地 ...
- 如何将一个已有的项目托管到github或是码云上?git的配置
场景一:已有的一个项目,要把它托管到Git上去,步骤和方法如下: 方法一: ①在工程的路径下 : git init 建一个裸仓库. ②远程仓库地址 :将本地的仓库和远程仓库关联 git remote ...
- 初识cocos creator的一些问题
本文的cocos creator版本为v1.9.01.color赋值cc.Label组件并没有颜色相关的属性,但是Node有color的属性. //如果4个参数,在ios下有问题let rgb = [ ...
- 学习网址Collect
Laravel 学院 https://laravelacademy.org/wx小程序 https://developers.weixin.qq.com/miniprogram/dev/quic ...
- struct-计算机学习日志
STRUCT实验目的模拟缓冲区溢出的情况.代码总览#include <stdio.h>#include <stdlib.h>typedef struct { int a[2]; ...
- 【转载】Jsp页面传Json数据到服务端,转对象或集合进行数据处理
需求:1.将页面数据带到服务端并转成对象,2.将页面的集合数据带到服务端转List实现:用ajax请求传递数据,数据格式为json JS方法: testJsonMethod = function(){ ...
- Python对JSON的操作 day3
下面将为大家介绍如何使用python语言来编码和解码json对象: json串就是一个字符串,json串必须用双引号,不能使用单引号 使用json函数需要导入json库,import json 1.j ...
- python写入Excel
一.dataframe存入Excel中: 注意:openpyxl打开的文件需是xlsx的后缀,因为比较新的. from openpyxl import load_workbook import pan ...
- Lua的string库函数、lua中string的模式匹配
--****************Lua的string库函数****************** --1.string.byte --string.byte (s [, i [, j]]) --取出 ...