链接:

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\n", ans);
} return 0;
}

LightOJ - 1246 - Colorful Board(DP)的更多相关文章

  1. LightOJ - 1246 Colorful Board(DP+组合数)

    http://lightoj.com/volume_showproblem.php?problem=1246 题意 有个(M+1)*(N+1)的棋盘,用k种颜色给它涂色,要求曼哈顿距离为奇数的格子之间 ...

  2. 1246 - Colorful Board

    1246 - Colorful Board    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB ...

  3. lightoj 1032 二进制的dp

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1032 #include <cstdio> #include <cst ...

  4. lightOJ 1017 Brush (III) DP

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...

  5. lightoj 1381 - Scientific Experiment dp

    1381 - Scientific Experiment Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.lightoj.com/vo ...

  6. LightOJ 1068 Investigation (数位dp)

    problem=1068">http://www.lightoj.com/volume_showproblem.php?problem=1068 求出区间[A,B]内能被K整除且各位数 ...

  7. Lightoj 1044 - Palindrome Partitioning (DP)

    题目链接: Lightoj  1044 - Palindrome Partitioning 题目描述: 给一个字符串,问至少分割多少次?分割出来的子串都是回文串. 解题思路: 先把给定串的所有子串是不 ...

  8. lightoj 1084 - Winter(dp+二分+线段树or其他数据结构)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1084 题解:不妨设dp[i] 表示考虑到第i个点时最少有几组那么 if a[i ...

  9. (LightOJ 1030)期望dp

    You are x N grid. Each cell of the cave can contain any amount of gold. Initially you are . Now each ...

随机推荐

  1. 超实用的 JavaScript 代码片段( ES6+ 编写)

    Array 数组 Array concatenation (数组拼接) 使用 Array.concat() ,通过在 args 中附加任何数组 和/或 值来拼接一个数组. const ArrayCon ...

  2. PMBOK(第六版) PMP备考知识总汇!

    记录本人学习PMBOK第六版的学习笔记. 备考知识总汇! PMBOK序章 PMP备考指南之相关事项介绍 PMP备考指南之第一章:引论 PMP备考指南之第二章:项目运作环境 PMP备考指南之第三章:项目 ...

  3. Java开发笔记(一百三十一)Swing的列表框

    前面介绍了选择框的用法,当时为了方便用户勾勾点点,无论是复选框还是单选按钮,统统把所有选项都摆在界面上.倘若只有两三个选项还好办,要是选项数量变多比如超过五个,这么多的选择框一齐在界面罗列,不光程序员 ...

  4. DNS欺诈的三种简单方法总结

    使用arpspoof.ettercap以及driftnet的简单组合. ①arpsppof+driftnet arpspoof -i eth0 -t 目标ip 目标网关 driftnet -i eth ...

  5. 视图集ViewSet

    一 .视图集ViewSet 使用视图集ViewSet,可以将一系列逻辑相关的动作放到一个类中: list() 提供一组数据 retrieve() 提供单个数据 create() 创建数据 update ...

  6. Modelsim——do脚本、bat命令

    一.do脚本实现自动化仿真 Modelsim是支持命令的,我们可以用 .do 文件将这些命令先写好然后在Modelsim上调用.因为我的编辑器不支持.do的语法,所以这里改用 .tcl文件,它和 .d ...

  7. Spring Cloud常用组件及各组件版本对应关系图

    Spring Cloud常用组件: 架构图: 版本对应关系:

  8. Springboot token令牌验证解决方案 在SpringBoot实现基于Token的用户身份验证

    1.首先了解一下Token 1.token也称作令牌,由uid+time+sign[+固定参数]组成: uid: 用户唯一身份标识 time: 当前时间的时间戳 sign: 签名, 使用 hash/e ...

  9. Jupyter交互式工具安装使用

    Jupyter交互式工具安装使用 Jupyter Notebook(此前被称为IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言. 文档:https://jupyter ...

  10. 分享大麦UWP版本开发历程-03.GridView或ListView 滚动底部自动加载后续数据

    今天跟大家分享的是大麦UWP客户端,在分类.订单或是搜索时都用到的一个小技巧,技术粗糙大神勿喷. 以大麦分类举例,默认打开的时候,会为用户展示20条数据,当用户滚动鼠标或者使用手势将列表滑动到倒数第二 ...