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. javascript——select 标签的使用

    <% String state = (String) request.getAttribute("state"); String day = (String) request ...

  2. 【转载】.NET/C#-uploadify视频文件or大文件上传

    引言 之前使用Uploadify做了一个上传图片并预览的功能,今天在项目中,要使用该插件上传大文件.之前弄过上传图片的demo,就使用该demo进行测试.可以查看我的这篇文章: [Asp.net]Up ...

  3. ASP.NET压力测试

    本文导读:对于直接面对互联网用户的WEB应用,在开发设计的时候必须格外小心,因为谁也不知道在单位时间内WEB程序访问和运行的速度.所以,在程序设计完成以后,最后针对程序进行一些严格的甚至是苛刻的测试, ...

  4. SharePoint CAML Query小结

    CAML的结构. <View Type="HTML" Name="Summary"> <ViewBody ExpandXML="TR ...

  5. IE DIV背景透明,点击事件不响应解决方案

    IE DIV背景透明,给DIV绑定点击事件, 当点击DIV时,不会响应已经绑定的点击事件. 解决方案是给DIV的设置以下样式. background-image: url(data:image/gif ...

  6. HTTPS 原理与证书实践

    1.1 网络安全知识 1.1.1 网结安全出现背景 网络就是实现不同主机之间的通讯,网络出现之初利用TCP/IP协议簇的相关协议概念,已经满足了互连两台主机之间可以进行通汛的目的,虽然看似简简单单几句 ...

  7. 15款不容错过的前端开发Javascript和css类库 - 2017版本~

    前端的JS和CSS类库日新月异, 在今天这篇介绍中,我们将精挑细选15款超棒的JS/CSS类库, 希望大家在开发过程中会觉得有帮助~ Core UI 基于Bootstrap4的一套UI类库, Core ...

  8. linux系统安装apache服务器

    命令行下安装: sudo apt-get install apache2 安装完毕以后, 打开127.0.0.1,可以看到首页: 静态页面的路径是: /var/www/html 作者: NONO 出处 ...

  9. VCAP5-DCA Objective 1.3 – Configure and Manage Complex Multipathing and PSA Plug-ins

    http://virtuallyhyper.com/2012/10/vcap5-dca-objective-1-3-configure-and-manage-complex-multipathing- ...

  10. Dicom格式文件解析器[转]

    Dicom格式文件解析器   Dicom全称是医学数字图像与通讯,这里讲的暂不涉及通讯那方面的问题 只讲*.dcm 也就是diocm格式文件的读取,读取本身是没啥难度的 无非就是字节码数据流处理.只不 ...