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

题解:

第一种方法是暴力深搜:枚举盘子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. “浪潮杯”第九届山东省ACM大学生程序设计竞赛重现赛 C-Cities

    题目描述:There are n cities in Byteland, and the ith city has a value ai. The cost of building a bidirec ...

  2. 7CSS之超链接

    <!-- title="这是鼠标悬停时显示的文字" 鼠标悬停时,显示相关的文字--> <a href="#" title="这是鼠标 ...

  3. 接口测试(一)--soapui实践

    一.接口的概念 接口是指系统模块与模块或系统与系统之间进行交互,一般用的多的是HTTP协议的接口.webService协议的接口,还有RPC的接口. RPC:Remote Procedure Call ...

  4. jQuery——节点操作

    创建节点 1.$():创建一个li标签 $("<li class='aaa'>我是li标签</li>") 2.html():创建一个li标签并同时添加到ul ...

  5. (转) Arcgis4js实现链家找房的效果

    http://blog.csdn.net/gisshixisheng/article/details/71009901 概述 买房的各位亲们不知是否留意过链家的"地图找房",这样的 ...

  6. iOS错误报告中关于崩溃地址的分析

    http://blog.csdn.net/gaoyp/article/details/46912753 一.错误报告中的三种地址:stack addressload addresssymbol add ...

  7. post发送数据 mypost input 改变事件

    //name=或者 "&name=" + "123" + "&data=" + "slice" (可以获 ...

  8. 一文读懂架构师都不知道的isinstance检查机制

    起步 通过内建方法 isinstance(object, classinfo) 可以判断一个对象是否是某个类的实例.但你是否想过关于鸭子协议的对象是如何进行判断的呢? 比如 list 类的父类是继 o ...

  9. BZOJ 2442: [Usaco2011 Open]修剪草坪 单调队列

    Code: #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...

  10. Python 模块的导入 day5

    一.模块 1.标准模块 python自带的 2.第三方模块 需要自己安装的模块 3.自己写的python文件 一个python文件,就是一个模块 (1)导入模块的实质 就是把你导入的模块运行了一遍 ( ...