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. AI-终极算法-神经网络(连结学派)

  2. mysql的水平拆分和垂直拆分 (转)

    http://www.cnblogs.com/sns007/p/5790838.html 1,水平分割: 例:QQ的登录表.假设QQ的用户有100亿,如果只有一张表,每个用户登录的时候数据库都要从这1 ...

  3. 添加 jar 包后需要做的配置

  4. linux bash关闭标准输出1(exec 1<&-)后重新打开

    linux bash shell的再次学习. 文件描述符: stdin,stdout 和 stderr 的文件描述符分别是 0,1 和 2(一个文件描述符说白了就是文件系统为了跟踪这个打开的文件而分配 ...

  5. (转)SVN服务器搭建和使用(三) 附vs2013 svn插件

    转自:http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2408089.html vs 2013 svn插件:http://www.visua ...

  6. 如何启动docker service

    From powershell prompt following works for me with no issues restart-service *docker* [注意] 我试了一下,这个命 ...

  7. 解决IE6兼容性问题的十一大技巧

    10要点解决IE6兼容性问题 1.使用声明 你必须经常在html网页头部放置一个声明,推荐使用严格的标准.例如 <!DOCTYPEHTMLPUBLIC“-//W3C//DTDHTML4.01// ...

  8. 微信小程序 - 动态背景图片实现

    很简单-就两步 wxml(遍历style的background-image路径即可) wxss(.ab)

  9. C++ 第三课:常量转义字符

    常量转义字符 以下的转义字符使普通字符表示不同的意义. 转义字符 描述 \' 单引号 \" 双引号 \\ 反斜杠 \0 空字符 \a 响铃 \b 后退 \f 走纸 \n 换行 \r 回车 \ ...

  10. 2019微信公开课Pro微信之夜内容笔记总结

    2019微信公开课Pro 微信之夜内容笔记总结 小程序入口 我的小程序 任务栏入口 线下扫码 搜索小程序 附近小程序升级 用户留存问题 小程序成长 关注用户需求 性能监控   广告主&& ...