• 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 }
  • 相关阅读:
    窗体吸附 Timer + 判断Location (简单实用)
    C# FTP 应用程序
    C# 加密方法汇总
    LINQ 标准的查询操作符 合计操作符 Count()、Sum()、Min()、Max()、Average()和Aggregate()
    委托中的协变和逆变(C# 编程指南)
    深入探讨C#序列化和反序列化
    grep 命令详解
    Oracle 数据库的启动和关闭的方式!
    linux 下的光盘拷贝
    C3P0连接池配置
  • 原文地址:https://www.cnblogs.com/xiong-/p/3667051.html
Copyright © 2020-2023  润新知