zoukankan      html  css  js  c++  java
  • hdu 4301 dp

    Divide Chocolate

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


    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
     

     题目大意:给你一块2*n的巧克力,求把它切成k块的切法。

     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 
     5 const int M=100000007;
     6 int d[1010][2020][2]={0};
     7 //i表示第i列,j表示分成j个,k表示最后一列的两种状态
     8 //0表示最后一列分成一块,1表示分成两块
     9 
    10 void init()
    11 {
    12     int i,j;
    13     d[1][1][0]=1;d[1][2][1]=1;
    14     for(i=2;i<=1000;i++)
    15     {
    16         for(j=1;j<=2*i;j++)
    17         {
    18             d[i][j][0]=(d[i-1][j][0]+2*d[i-1][j][1]+d[i-1][j-1][0]+d[i-1][j-1][1])%M;
    19             d[i][j][1]=(d[i-1][j][1]+2*d[i-1][j-1][0]+2*d[i-1][j-1][1]+d[i-1][j-2][0]+d[i-1][j-2][1])%M;
    20         }
    21     }
    22 }
    23 int main()
    24 {
    25     int n,k,t;
    26     init();
    27     scanf("%d",&t);
    28     while(t--)
    29     {
    30         scanf("%d %d",&n,&k);
    31         printf("%d
    ",(d[n][k][0]+d[n][k][1])%M);
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    java基本数据类型及运算的注意事项
    B-Tree 和 B+Tree 结构及应用,InnoDB 引擎, MyISAM 引擎
    软件工程与软件开发模型、软件开发方法
    2020年3月份Unity3D游戏源码合集-免费下载
    独立游戏开发必备!8个效果不错的Unity3D 免费模型资源包
    2019年4月份整理的Unity3D 20个实用插件-免费下载
    2019年4月份整理的Unity3D游戏完整源码
    2019年3月整理的2D美术资源合集
    画面效果都不错!20个精品Unity3D着色器插件
    Unity3D中UnityPlayerActivity与UnityPlayerNativeActivity有什么区别
  • 原文地址:https://www.cnblogs.com/xiong-/p/3667051.html
Copyright © 2011-2022 走看看