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. Medline Plus

    提问地址: http://apps2.nlm.nih.gov/medlineplus/contact/index.cfm?lang=en&from=http://www.nlm.nih.gov ...

  2. bash shell中可以使用wait

    https://jingyan.baidu.com/article/b907e6278fbd8946e7891c17.html ==================================== ...

  3. Eclipse Maven项目报错2之A child container failed during start

    问题:在同事那里拿了一个Eclipse的maven项目,导入报错,主要显示的是A child container failed during start 具体错误如下 六月 02, 2018 12:0 ...

  4. IIS中的application总是报404错误

      在IIS的一个站点下面建立了一个application,访问其中页面的时候总是报404(找不到页面)的错误,哪怕是最简单只包含一个简单html页面的application也是如此,而其他同级的ap ...

  5. Sublime 3156 LICENSE key

    mac sublime3 3156 LICENSE 转自:http://blog.csdn.net/myboyliu2007/article/details/78748253 下载地址:https:/ ...

  6. 跨域资源共享(CORS)--跨域ajax

    几年前,网站开发者都因为ajax的同源策略而撞了南墙.当我们惊叹于XMLHttpRequest对象跨浏览器支持所带来的巨大进步时,我们很快发现没有一个方法可以使我们用JavaScript实现请求跨域访 ...

  7. Ext JS isField为空或不是对象问题的解决

    在做Ext Js的DataGrid的时候经常会遇到这种问题,火狐谷歌没有问题,IE8及以下版本就无法通过,经调试会提示: “isField为空或不是对象问题的解决” 这通常是我们在js代码中多加了一个 ...

  8. 【指导】SonarQube 部署说明

    转载:https://blog.csdn.net/cuiaamay/article/details/52057091 1,安装 1.1 安装依赖 需要保证Oracle JRE 8 及以上,或者 Ope ...

  9. JavaScript String 对象常用方法

    <script type="text/javascript"> //concat() – 将两个或多个字符的文本组合起来,返回一个新的字符串. var str = &q ...

  10. Hierarchical query-层次查询之START WITH CONNECT BY用法

    Hierarchical query-层次查询中start with...connect by prior子句用法: connect by 是结构化查询中用到的,其基本语法是:  select ... ...