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 }
  • 相关阅读:
    Jquery操作select
    Session在类库中的使用
    从一个表取数据更新另一个表的信息
    判断数据库表中是否存在某个字段
    .net项目中上传的图片或者文件太大 无法上传
    计算机中丢失 msvcr110.dlll
    Ubuntu搭建FTP server
    Linux常用命令集
    系统清理篇
    ubuntu安装 ssh server
  • 原文地址:https://www.cnblogs.com/xiong-/p/3667051.html
Copyright © 2011-2022 走看看