Divide Chocolate

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1465    Accepted Submission(s): 682

Problem Description
It is well known that claire likes dessert very much, especially chocolate. But as a girl she also focuses on the intake of calories each day. To satisfy both of the two desires, claire makes a decision that each chocolate should be divided into several parts, and each time she will enjoy only one part of the chocolate. Obviously clever claire can easily accomplish the division, but she is curious about how many ways there are to divide the chocolate.

To simplify this problem, the chocolate can be seen as a rectangular contains n*2 grids (see above). And for a legal division plan, each part contains one or more grids that are connected. We say two grids are connected only if they share an edge with each other or they are both connected with a third grid that belongs to the same part. And please note, because of the amazing craft, each grid is different with others, so symmetrical division methods should be seen as different.
 
Input
First line of the input contains one integer indicates the number of test cases. For each case, there is a single line containing two integers n (1<=n<=1000) and k (1<=k<=2*n).n denotes the size of the chocolate and k denotes the number of parts claire wants to divide it into.
 
Output
For each case please print the answer (the number of different ways to divide the chocolate) module 100000007 in a single line.�
 
Sample Input
2
2 1
5 2
 
Sample Output
1
45
 
Author
BUPT
 
Source
 
Recommend
zhuyuanchen520
 

题目的意思是:给你n*2这么大的巧克力 ,要分成M种,问你有多少种分法。

    先定义dp[i][j][z],i表示第i列,j表示i列内分成j部分,z表示第i列的两块巧克力处于分开的状态还合并的。

所以 , 如果添加第i+1列则有三种情况:

1,  还是j部分,也就是不加部分 :dp[i][j][1]=dp[i-1][j][0]*2+dp[i-1][j][1] ;   dp[i][j][0]=dp[i-1][j][0];

2,       加一部分,j+1:   dp[i][j][1]=dp[i-1][j-1][0]+dp[i-1][j-1][1];     dp[i][j][0]=dp[i-1][j-1][1]+dp[i-1][j-1][1]+2*dp[i-1][j-1][0];

3,       加两部分,j+2:   dp[i][j][0]=dp[i-1][j-2][1]+dp[i-1][j-2][0];

这里有个图可以帮助理解:http://blog.csdn.net/youngyangyang04/article/details/7764817

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int N=;
const int mod=; int dp[N][N+N][]; //dp[i][j][z],i表示第i列,j表示i列内分成j部分,z表示第i列的两块巧克力处于分开的状态还合并的(0:分开,1:合并) int main(){ //freopen("input.txt","r",stdin); int t,n,k;
memset(dp,,sizeof(dp));
dp[][][]=;dp[][][]=;
for(int i=;i<N;i++){
for(int j=;j<=i*;j++){
dp[i][j][]=(*dp[i-][j][]+dp[i-][j][]+dp[i-][j-][]+dp[i-][j-][])%mod;
dp[i][j][]=(dp[i-][j][]+*dp[i-][j-][]+*dp[i-][j-][]+dp[i-][j-][]+dp[i-][j-][])%mod;
}
}
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&k);
printf("%d\n",(dp[n][k][]+dp[n][k][])%mod);
}
return ;
}

HDU 4301 Divide Chocolate (DP + 递推)的更多相关文章

  1. HDU 6076 Security Check DP递推优化

    Security Check Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) ...

  2. HDU 4301 Divide Chocolate(DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4301 题意: 有一块n*2大小的巧克力,现在某人要将这巧克力分成k个部分,每个部分大小随意,问有多少种分法. 思 ...

  3. HDU Tickets(简单的dp递推)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  4. hdu2089(数位DP 递推形式)

    不要62 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. 题解报告:hdu 2084 数塔(递推dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2084 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这 ...

  6. hdu 2604 Queuing(dp递推)

    昨晚搞的第二道矩阵快速幂,一开始我还想直接套个矩阵上去(原谅哥模板题做多了),后来看清楚题意后觉得有点像之前做的数位dp的水题,于是就用数位dp的方法去分析,推了好一会总算推出它的递推关系式了(还是菜 ...

  7. hdu 1723 DP/递推

    题意:有一队人(人数 ≥ 1),开头一个人要将消息传到末尾一个人那里,规定每次最多可以向后传n个人,问共有多少种传达方式. 这道题我刚拿到手没有想过 DP ,我觉得这样传消息其实很像 Fibonacc ...

  8. HDU 2154 跳舞毯 | DP | 递推 | 规律

    Description 由于长期缺乏运动,小黑发现自己的身材臃肿了许多,于是他想健身,更准确地说是减肥. 小黑买来一块圆形的毯子,把它们分成三等分,分别标上A,B,C,称之为“跳舞毯”,他的运动方式是 ...

  9. hdu 1284 钱币兑换问题 (递推 || DP || 母函数)

    钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

随机推荐

  1. Eclipse 文件太长,导致着色异常问题

    1. 把C/C++ ->Editor->Scalability, 对应红框中的数字调大.

  2. [Canvas]越来越近的女孩

    本作比前作增加了控制功能,观看动态效果请点此下载代码用Chrome或Firfox浏览器观看. 图例: 代码: <!DOCTYPE html> <html lang="utf ...

  3. SpringBoot 启动错误搜集

    Spring Boot:The Bean Validation API is on the classpath but no implementation could be found https:/ ...

  4. UIFont字体大全

    原文地址:UIFont 设置字体作者:青竹居士     http://deep-fish.iteye.com/blog/1678874UIFont 设置字体 1 label.font = [UIFon ...

  5. iOS开发点滴 - 如何通过Segue写代码传递数据从一个ViewController到另一个ViewController(Swift代码)

    1. 拖线 按住Control键,用鼠标从源控制器的某个控件开始,拖动到目的控制器 2. 选择弹出类型并设置Segue Identifier 在弹出的对话框中,选择“Selection Segue-& ...

  6. Go语言中使用MySql数据库

    Go语言中使用MySql数据库 1.MySQL驱动 Go中支持MySQL的驱动目前比较多,有如下几种,有些是支持database/sql标准,而有些是采用了自己的实现接口,常用的有如下几种: http ...

  7. Struts2(九)OGNL标签一与Struts2标签

    一.什么是OGNL  Object Graph Navigation Language对象图导航语言. 是Struts2默认的表达式语言,开源,功能更强大.和EL表达式有点相似 存取对象的属性,调用对 ...

  8. 安装 mysql-5.6.4-m7

    1.首先下载:http://cdn1.mydown.yesky.com/soft/201403/mysql-5.6.4-m7.tar.gz 2.解压,进入目录,执行cmake ./(如果没有cmake ...

  9. WIN下Git GUI 教程

    现在很多都有git来托管项目或者来查找资料,但是看起来操作不是很方便,现在由于win下可以直接使用git gui,让使用git变得方便,当然这只是针对日常简单的使用,如果想详细的使用,可以去参考廖学峰 ...

  10. Mule 入门之:环境搭建

    Mule 入门之:环境搭建 JDK1.5或以上版本Eclipse3.3以上 下载与安装:目前最新版本为2.2.1 下载,下载后得到一名为mule-standalone-2.2.1.zip的压缩文件,解 ...