题意:中文题目,不解释。。。

题解:

第一种方法是暴力深搜:枚举盘子1~n放苹果数量的所有情况,不需要剪枝;将每次枚举的情况,即每个盘的苹果数量,以字典序排序,然后存进set里 以此去重像"5 1 1"和"1 5 1"这种相同情况。

 /**
* @author Wixson
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <map>
#include <set>
const int inf=0x3f3f3f3f;
const double PI=acos(-1.0);
const double EPS=1e-;
using namespace std;
typedef long long ll;
typedef pair<int,int> P; int n,m;
set<string> s;
set<string>::iterator ite;
int ans;
char str[];
void dfs(int pos,int left)
{
if(pos==n-)
{
str[pos]=''+left,str[n]='\0';
string temp=str;
sort(temp.begin(),temp.end());
if((ite=s.find(temp))==s.end())
{
s.insert(temp);
ans++;
}
return;
}
//
for(int i=;i<=left;i++)
{
str[pos]=''+i;
dfs(pos+,left-i);
}
}
int main()
{
//freopen("input.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
ans=;
s.clear();
dfs(,m);
printf("%d\n",ans);
}
return ;
}

第二种方法: 递推。利用dp的思想,来看下样例:将7个苹果放进3个盘子里,可以分2种情况考虑:1.空着一个盘子不放,即将7个苹果放进2个盘子里;2.先每个盘子均放进一个苹果,然后将剩下的4个苹果放进3个盘子里。即dp[m][n]=dp[m-1][n]+dp[m-n][n](m>=n),  另外,显而易见 dp[m][n]=dp[m][m](m<n),dp[m][n]=1(m或n中有为1或0时);

 /**
* @author Wixson
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <map>
#include <set>
const int inf=0x3f3f3f3f;
const double PI=acos(-1.0);
const double EPS=1e-;
using namespace std;
typedef long long ll;
typedef pair<int,int> P; int n,m;
int dp(int m,int n)
{
if(!n||!m||m==||n==) return ;
if(m>=n) return dp(m,n-)+dp(m-n,n);
else return dp(m,m);
}
int main()
{
//freopen("input.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
printf("%d\n",dp(m,n));
}
return ;
}

poj 1664 放苹果 (划分数)的更多相关文章

  1. poj 1664 放苹果(递推)

    题目链接:http://poj.org/problem? id=1664 放苹果 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions ...

  2. poj 1664 放苹果 递归

    题目链接: http://poj.org/problem?id=1664 题目描述: 有n个苹果,m个盒子,盒子和苹果都没有顺序,盒子可以为空,问:有多少种放置方式? 解题思路: 当前有n个苹果,m个 ...

  3. POJ 1664 放苹果 (递推思想)

    原题链接:http://poj.org/problem?id=1664 思路:苹果m个,盘子n个.假设 f ( m , n ) 代表 m 个苹果,n个盘子有 f ( m , n ) 种放法. 根据 n ...

  4. POJ 1664 放苹果

    放苹果 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24985   Accepted: 15908 Description ...

  5. poj 1664放苹果(递归)

    放苹果 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37377   Accepted: 23016 Description ...

  6. poj 1664 放苹果(dfs)

    放苹果 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30284   Accepted: 19098 Description ...

  7. POJ 1664 放苹果 (递推)

    题目链接:http://poj.org/problem?id=1664 dp[i][j]表示i个盘放j个苹果的方案数,dp[i][j] 可以由 dp[i - 1][j] 和 dp[i][j - i] ...

  8. OpenJudge/Poj 1664 放苹果

    1.链接地址: http://bailian.openjudge.cn/practice/1664 http://poj.org/problem?id=1664 2.题目: 总时间限制: 1000ms ...

  9. POJ 1664 放苹果(递归或DP)

    一.Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法. Input 第一行是测试数据的数目t ...

随机推荐

  1. 在Windows2003安装配置Bitvise SSH Server后,不能使用软件内建立的用户登录!

    Google:  I can only log in with an administrator account - attempting to log in with a regular accou ...

  2. 6.11---@RequestMapping注解的6+2个属性---6.11

    produces:它的作用是指定返回值类型,不但可以设置返回值类型还可以设定返回值的字符编码: consumes: 指定处理请求的提交内容类型(Content-Type),例如application/ ...

  3. 百度之星2017初赛B1006 小小粉丝度度熊

    思路: 考虑到补签卡一定是连续放置才更优,所以直接根据起始位置枚举.预先处理区间之间的gap的前缀和,在枚举过程中二分即可.复杂度O(nlog(n)). 实现: #include <iostre ...

  4. 关于编辑器对<input>标签报错提示“表单输入没有相关label”的问题

    相信很多朋友在制作表单的时候,我们的编辑器会有下图的相关提示吧 我们发现虽然这样并不影响我们的正常使用,但是看着这样的报错提示总是很让人心烦,那么这到底是为什么呢? 其实,这是因为编辑器建议我们在使用 ...

  5. HTML CSS, JavaScript 计算器

    效果图: 代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...

  6. 六时车主 App 隐私政策

    六时车主 App 隐私政策   本应用尊重并保护所有使用服务用户的个人隐私权.为了给您提供更准确.更有个性化的服务,本应用会按照本隐私权政策的规定使用和披露您的个人信息.但本应用将以高度的勤勉.审慎义 ...

  7. 【译】x86程序员手册12-4.2系统指令

    4.2 Systems Instructions 系统指令 Systems instructions deal with such functions as: 系统指令具有以下功能: Verifica ...

  8. VMware Workstation Pro 15 for Windows下载与安装

    VMware Workstation Pro 15 for Windows下载与安装 一.下载 下载地址:https://my.vmware.com/cn/web/vmware/details?dow ...

  9. 零基础到精通Linux,从这篇文章开始

    2018年想做Linux运维的人应该如何学习才能快速精通Linux? Linux入门这么简单,为什么很多人学不会? 想要成为一个合格的运维工程师,到底怎么才能从零开始精通Linux? 作为一个运维小白 ...

  10. lua_note_01_lua介绍

    1. lua 1. lua 1.1. lua介绍 1.2. Lua 特性 1.3. 特点 1.4. Lua 应用场景 1.5. 环境搭建 1.6. VS lua 1.1. lua介绍 Lua 是一种轻 ...