hdu 4301 - Divide Chocolate(简单dp)


题目:

Divide Chocolate


题意:

将一块n*2的巧克力分成k份的不同分法总数,对称视为不同种


思路:

一列一列地枚举情况:

dp[i][j][state] : 表示将i * 2的巧克力分成j块 , 其中 state = 1表示最后的一列是被分割的状态, state=0表示最后的一列是连起来的状态


则举例如下状况:dp[i-1][j][0] , 前i-1列被分成了j块,其中的最后一列( i -1 列)是连起来的,现在要将当前列的巧克力整合上去,由于已经有j块了,不能再增加,故不论是割开还是不割开,只能一起粘上去。

其余情况类推


代码:

//#pragma comment(linker, "/STACK:102400000,102400000")
#include "iostream"
#include "cstring"
#include "algorithm"
#include "cmath"
#include "cstdio"
#include "sstream"
#include "queue"
#include "vector"
#include "string"
#include "stack"
#include "cstdlib"
#include "deque"
#include "fstream"
#include "map"
using namespace std;
typedef long long LL;
const int INF = 522133279;
const int MAXN = 1000000+100;
#define eps 1e-14
const int mod = 100000007;

LL dp[1010][2010][2];

int main()
{

    //freopen("in","r",stdin);
    //freopen("out","w",stdout);

    int t;
    scanf("%d",&t);

    dp[1][1][0] = 1;
    dp[1][2][1] = 1;

    for(int i = 2 ; i <= 1000 ; i++)
        for(int j = 1 ; j <= i*2 ; j++)
        {
            dp[i][j][0] = (dp[i-1][j][0] + 2*dp[i-1][j][1] + dp[i-1][j-1][1] + dp[i-1][j-1][0]) %mod;
            dp[i][j][1] = (dp[i-1][j][1] + dp[i-1][j-2][0] + dp[i-1][j-2][1] + 2*dp[i-1][j-1][0] + 2*dp[i-1][j-1][1]) % mod;
        }

    for(int ka = 1 ; ka <= t ; ka++)
    {
        int n,k;
        scanf("%d%d",&n,&k);

        printf("%lld\n" , (dp[n][k][0] + dp[n][k][1])%mod);
    }

    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章