zoukankan      html  css  js  c++  java
  • LightOJ

    链接:

    https://vjudge.net/problem/LightOJ-1246

    题意:

    You are given a rectangular board. You are asked to draw M horizontal lines and N vertical lines in that board, so that the whole board will be divided into (M+1) x (N+1) cells. So, there will be M+1 rows each of which will exactly contain N+1 cells or columns. The yth cell of xth row can be called as cell(x, y). The distance between two cells is the summation of row difference and column difference of those two cells. So, the distance between cell(x1, y1) and cell(x2, y2) is

    |x1 - x2| + |y1 - y2|

    For example, the distance between cell (2, 3) and cell (3, 2) is |2 - 3| + |3 - 2| = 1 + 1 = 2.

    After that you have to color every cell of the board. For that you are given K different colors. To make the board more beautiful you have to make sure that no two cells having the same color can have odd distance between them. For example, if you color cell (3, 5) with red, you cannot color cell (5, 8) with red, as the distance between them is 5, which is odd. Note that you can keep some color unused, but you can't keep some cell uncolored.

    You have to determine how many ways to color the board using those K colors.

    思路:

    将图分为两个部分,任意一个部分的点到另一个部分的任意一个点的距离都是奇数。
    这样就转变成了一个DP,Dp[i][j]表示n个位置,放了j种颜色。
    Dp[i][j] = Dp[i-1][j-1]j+Dp[i-1][j]j
    再用组合数分配一下两个部分的颜色。

    代码:

    // #include<bits/stdc++.h>
    #include<iostream>
    #include<cstdio>
    #include<vector>
    #include<string.h>
    #include<set>
    #include<queue>
    #include<algorithm>
    #include<math.h>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    const int MOD = 1e9+7;
    const int MAXN = 1e6+10;
    
    int n, m, k;
    LL Dp[410][55];
    LL c[55][55];
    
    void Init()
    {
        memset(c, 0, sizeof(c));
        for (int i = 0;i < 55;i++)
        {
            c[i][0] = 1;
            for (int j = 1;j <= i;j++)
            {
                c[i][j] = (c[i-1][j-1] + c[i-1][j])%MOD;
            }
        }
        for (int i = 1;i < 410;i++)
        {
            Dp[i][1] = 1;
            for (int j = 2;j < 55;j++)
            {
                Dp[i][j] = (Dp[i-1][j-1]*j+Dp[i-1][j]*j)%MOD;
            }
        }
    }
    
    int main()
    {
        // freopen("test.in", "r", stdin);
        Init();
        int t, cas = 0;
        scanf("%d", &t);
        while(t--)
        {
            printf("Case %d:", ++cas);
            scanf("%d%d%d", &n, &m, &k);
            n++, m++;
            LL ans = 0;
            if (n == m && m == 1)
                ans = k;
            else
            {
                int sum1 = 0, sum2 = 0;
                sum1 = ((n+1)/2)*((m+1)/2)+(n/2)*(m/2);
                sum2 = n*m-sum1;
                for (int i = 1;i < k;i++)
                {
                    for (int j = 1;i+j <= k;j++)
                        ans = (ans + c[k][i]*c[k-i][j]%MOD*Dp[sum1][i]%MOD*Dp[sum2][j]%MOD)%MOD;
                }
            }
            printf(" %lld
    ", ans);
        }
    
        return 0;
    }
    
  • 相关阅读:
    网络需求分析课堂作业
    工程招标与投标课堂作业
    burpsuite Pro下载安装及破解 | JDK安装和配置
    渗透测试环境的搭建
    web应用基础架构
    为Linux环境安装图形化界面
    Linux基本操作
    markdown语法教程(更新中)
    VMware导入和删除虚拟机文件
    Java求幂集与List的浅拷贝深拷贝问题
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12019331.html
Copyright © 2011-2022 走看看