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

题解:

第一种方法是暴力深搜:枚举盘子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. 【NOIP2016】DAY1 T2 天天爱跑步

    [NOIP2016]DAY1 T2 天天爱跑步 Description 小c同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.?天天爱跑步?是一个养成类游戏,需要玩家每天按时 ...

  2. Elasticsearch集群状态健康值处于red状态问题分析与解决(图文详解)

      问题详情 我的es集群,开启后,都好久了,一直报red状态??? 问题分析 有两个分片数据好像丢了.   不知道你这数据怎么丢的. 确认下本地到底还有没有,本地要是确认没了,那数据就丢了,删除索引 ...

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

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

  4. SQL Server 2008R2 Set IDENTITY_INSERT 表名 ON/OFF不能与insert into select 的语句一起执行?

    大家都知数据库表中的列可以自增长,但是有时候我们需要插入数据的时候会指定这一列的数据. 这时候我们可以很简单的利用sql语句来执行新增一条的数据,如下: set IDENTITY_INSER 表名 o ...

  5. Google广告屏蔽插件adBlock

    今天在博客园写博客的时候发现莫名其妙的在右侧被植入了广告,询问了管理员得知存在以下几种可能: 1.电信网络供应商劫持网页,植入广告 2.ADSafe(是一款去除广告的软件,效果很不错) 但经过最终排除 ...

  6. 新认知之WinForm窗体程序

    Windows应用程序和控制台应用程序有很大的区别 >Form1.cs  :窗体文件,程序员对窗体编写的代码一般都存放在这个文件中. >Form1.Designer.cs :窗体设计文件, ...

  7. C#语言最基础的认识变量

    变量是指一块存储数据的内存空间,并且该内存区域的数据内容可以发生变化. 变量是必须先声明后赋值. 基本的语法:数据类型+变量名: 变量名=数据: 简单的使用技巧:声明赋值简写 Static void ...

  8. tomcat报错org.springframework.web.context.ContextLoaderListener找不到

    tomcat报错org.springframework.web.context.ContextLoaderListener找不到. 最后解决办法:将jar包copy到web-inf下面的lib中. 你 ...

  9. html5——伸缩布局

    基本概念 1.主轴:Flex容器的主轴主要用来配置Flex项目,默认是水平方向 2.侧轴:与主轴垂直的轴称作侧轴,默认是垂直方向的 3.方向:默认主轴从左向右,侧轴默认从上到下 4.主轴和侧轴并不是固 ...

  10. (转)Hibernate的优化方案

    http://blog.csdn.net/yerenyuan_pku/article/details/70768603 HQL优化 使用参数绑定  使用绑定参数的原因是让数据库一次解析SQL,对后续的 ...