LightOJ - 1246 - Colorful Board(DP)
链接:
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)的更多相关文章
- LightOJ - 1246 Colorful Board(DP+组合数)
http://lightoj.com/volume_showproblem.php?problem=1246 题意 有个(M+1)*(N+1)的棋盘,用k种颜色给它涂色,要求曼哈顿距离为奇数的格子之间 ...
- 1246 - Colorful Board
1246 - Colorful Board PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB ...
- lightoj 1032 二进制的dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1032 #include <cstdio> #include <cst ...
- lightOJ 1017 Brush (III) DP
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...
- lightoj 1381 - Scientific Experiment dp
1381 - Scientific Experiment Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lightoj.com/vo ...
- LightOJ 1068 Investigation (数位dp)
problem=1068">http://www.lightoj.com/volume_showproblem.php?problem=1068 求出区间[A,B]内能被K整除且各位数 ...
- Lightoj 1044 - Palindrome Partitioning (DP)
题目链接: Lightoj 1044 - Palindrome Partitioning 题目描述: 给一个字符串,问至少分割多少次?分割出来的子串都是回文串. 解题思路: 先把给定串的所有子串是不 ...
- lightoj 1084 - Winter(dp+二分+线段树or其他数据结构)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1084 题解:不妨设dp[i] 表示考虑到第i个点时最少有几组那么 if a[i ...
- (LightOJ 1030)期望dp
You are x N grid. Each cell of the cave can contain any amount of gold. Initially you are . Now each ...
随机推荐
- nginx acces.log日志分析
1,统计各访问IP的总数 awk '{if($9>0 && $9==200 && substr($6,2)== "GET") a[$1]++} ...
- [转帖]VMware vSphere 6 序列号大全
VMware vSphere 6 序列号大全 https://blog.csdn.net/sj349781478/article/details/82378244 经过测试ESXI6.5也可以使用 ...
- Docker部署ELK 7.0.1集群之Kibana安装介绍
1.下载镜像 [root@vanje-dev01 ~]# docker pull kibana: 2.安装部署 2.1 创建宿主机映射目录 [root@vanje-dev01 ~]# mkdir /e ...
- C++的派生类构造函数是否要带上基类构造函数
//public:Student(int s_age):People(s_age) //C++的派生类构造函数后面是否带上基类构造函数,取决于基类构造函数是否需要传入参数,如果要参数,就一定带上:不需 ...
- const指针和指向常量的指针
先看下面六种写法: . const int p; . const int *p; . int const* p; . int * const p; . const int * const p; . i ...
- Java -- 最简单的认识重载
定义 方法的名称相同,参数个数或类型不同的时候就成为方法重载. 示例 编写一个两个数相加的方法: public class hello{ public static void main(String ...
- appium1.6在mac上环境搭建启动ios模拟器上Safari浏览器 转自:上海-悠悠
前言 在mac上搭建appium踩了不少坑,先是版本低了,启动后无限重启模拟器.后来全部升级最新版本,就稳稳的了. 环境准备: 1.OS版本号10.12 2.xcode版本号8.3.2 3.appiu ...
- Unity项目 - 坦克大战3D TankBattle
目录 游戏原型 项目演示 绘图资源 代码实现 技术探讨 参考来源 游戏原型 游戏玩法:在有界的战场上,玩家将驾驶坦克,代表绿色阵营,与你的队友一起击溃红蓝阵营的敌人,在这场三方大战中夺得胜利! 操作指 ...
- lombok使用教程
Lombok介绍.使用方法和总结https://www.cnblogs.com/heyonggang/p/8638374.html Lombok简介.使用.工作原理.优缺点https://www.ji ...
- 前端开发 Vue Vue.js和Nodejs的关系
首先vue.js 是库,不是框架,不是框架,不是框架. Vue.js 使用了基于 HTML 的模版语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据. Vue.js 的核心是一个允许你 ...