1246 - Colorful Board
Time Limit: 2 second(s) | Memory Limit: 32 MB |
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.
Input
Input starts with an integer T (≤ 20000), denoting the number of test cases.
Each case starts with a line containing three integers M, N, K (0 ≤ M, N ≤ 19, 1 ≤ K ≤ 50).
Output
For each case, print the case number and the number of ways you can color the board. The result can be large, so print the result modulo 1000000007.
Sample Input |
Output for Sample Input |
4 0 0 1 0 0 2 5 5 2 5 5 1 |
Case 1: 1 Case 2: 2 Case 3: 2 Case 4: 0 |
Time Limit: 2 second(s) | Memory Limit: 32 MB |
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.
Input
Input starts with an integer T (≤ 20000), denoting the number of test cases.
Each case starts with a line containing three integers M, N, K (0 ≤ M, N ≤ 19, 1 ≤ K ≤ 50).
Output
For each case, print the case number and the number of ways you can color the board. The result can be large, so print the result modulo 1000000007.
Sample Input |
Output for Sample Input |
4 0 0 1 0 0 2 5 5 2 5 5 1 |
Case 1: 1 Case 2: 2 Case 3: 2 Case 4: 0 |

1 #include<stdio.h>
2 #include<algorithm>
3 #include<string.h>
4 #include<iostream>
5 using namespace std;
6 typedef long long LL;
7 const LL N= 1000000007;
8 LL yan[1005][1005];
9 LL STL[1005][1005];
10 LL pp[1005];
11 LL quick(LL n,LL m);
12 int main(void)
13 {
14 int i,j,k;
15 scanf("%d",&k);
16 int s;
17 yan[0][0]=1;
18 for(i=1; i<=1000; i++)
19 {
20 for(j=0; j<=i; j++)
21 {
22 if(j==0||i==j)
23 yan[i][j]=1;
24 else
25 {
26 yan[i][j]=(yan[i-1][j]+yan[i-1][j-1])%N;
27 }
28 }
29 }
30 pp[0]=1;
31 for(i=1;i<=1000;i++)
32 pp[i]=(pp[i-1]*i)%N;
33 memset(STL,0,sizeof(STL));
34 STL[0][0]=1;
35 STL[1][0]=0;
36 STL[1][1]=1;
37 for(i=2; i<=1000; i++)
38 {
39 for(j=1; j<=i; j++)
40 {
41 if(j==1||i==j)
42 STL[i][j]=1;
43 else
44 {
45 STL[i][j]=((STL[i-1][j]*j)%N+STL[i-1][j-1])%N;
46 }
47 }
48 }
49 for(s=1; s<=k; s++)
50 {
51 int x1,x2,x3,x4;
52 scanf("%d %d %d",&x1,&x2,&x3);
53 x1+=1;
54 x2+=1;
55 LL sum=(x1*x2);
56 LL he=(sum+1)/2;
57 LL cnt=0;
58 for(i=1; i<=min((LL)x3,he); i++)
59 {
60 LL x=x3-i;
61 LL kk=quick(x,sum-he);
62 LL ak=((STL[he][i]*yan[x3][i]%N)*kk)%N;
63 cnt=(cnt+ak*pp[i]%N)%N;
64 }
65 printf("Case %d: ",s);
66 printf("%lld\n",cnt);
67 }
68 return 0;
69 }
70
71 LL quick(LL n,LL m)
72 {
73 LL ans=1;n%=N;
74 while(m)
75 {
76 if(m&1)
77 ans=(ans*n)%N;
78 n=(n*n)%N;
79 m/=2;
80 }
81 return ans;
82 }
1246 - Colorful Board的更多相关文章
- LightOJ - 1246 Colorful Board(DP+组合数)
http://lightoj.com/volume_showproblem.php?problem=1246 题意 有个(M+1)*(N+1)的棋盘,用k种颜色给它涂色,要求曼哈顿距离为奇数的格子之间 ...
- LightOJ - 1246 - Colorful Board(DP)
链接: https://vjudge.net/problem/LightOJ-1246 题意: You are given a rectangular board. You are asked to ...
- AC日记——丑数 codevs 1246
1246 丑数 USACO 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Description 对于一给定的素 ...
- [LeetCode] Battleships in a Board 平板上的战船
Given an 2D board, count how many different battleships are in it. The battleships are represented w ...
- UP Board 串口使用心得
前言 原创文章,转载引用务必注明链接. 本文使用Markdown写成,为获得更好的阅读体验和正常的图片.链接,请访问我的博客: http://www.cnblogs.com/sjqlwy/p/up_s ...
- UP Board 网络设置一本通
前言 原创文章,转载引用务必注明链接,水平有限,欢迎指正. 本文环境:ubilinux 3.0 on UP Board 本文使用Markdown写成,为获得更好的阅读体验和正常的图片.链接,请访问我的 ...
- UP Board USB无线网卡一贴通
前言 原创文章,转载引用务必注明链接,水平有限,欢迎指正. 本文环境:ubilinux 3.0 kernel 4.4.0 本文使用Markdown写成,为获得更好的阅读体验和正常的图片.链接,请访问我 ...
- 在UP Board 上搭建M——L服务器
前言 原创文章,转载引用务必注明链接,水平有限,欢迎指正. 本文环境:ubilinux 3.0 on UP Board 初识免流 所谓免流,就是免除手机访问网络产生的流量费用.其原理在乌云网上有过报道 ...
- UP Board 妄图启动ubilinux失败
前言 原创文章,转载引用务必注明链接. 经历了上次的上电开机失败,我们终于发现需要手动为UP板安装系统,因为没有显示器的Headless模式时,使用Linux比较方便,另外熟悉Debian系的,所以选 ...
随机推荐
- lvm 创建扩展
fdisk /dev/sdgnpt8ewpartprobepvcreate /dev/sdg1vgcreate multibank /dev/sdg1lvcreate -l +100%FREE -n ...
- 【分布式】Zookeeper的Leader选举-选举过程介绍(经典的Paxos算法解析)
一.前言 前面学习了Zookeeper服务端的相关细节,其中对于集群启动而言,很重要的一部分就是Leader选举,接着就开始深入学习Leader选举. 二.Leader选举 2.1 Leader选举概 ...
- Linux学习 - 系统命令sudo权限
1 功能 root把超级用执行的命令赋予普通用户执行 2 使用 visudo 或 vim /etc/sudoers 说明: root 用户名 ALL=(ALL) 被管理主机的地址=(可使用的身份) A ...
- Can references refer to invalid location in C++?
在C++中,引用比指针更加的安全,一方面是因为引用咋定义时必须进行初始化,另一方面是引用一旦被初始化就无法使其与其他对象相关联. 但是,在使用引用的地方仍然会有一些例外. (1)Reference t ...
- SpringBoot(4):整合Mybatis
1. 导入mybatis所需要的依赖 1 <!-- 引入 myBatis,这是 MyBatis官方提供的适配 Spring Boot的--> 2 <dependency> 3 ...
- Linux系统的负载与CPU、内存、硬盘、用户数监控的shell脚本
利用Shell脚本来监控Linux系统的负载.CPU.内存.硬盘.用户登录数. 这几天在学习研究shell脚本,写的一些系统负载.CPU.内存.硬盘.用户数监控脚本程序.在没有nagios监控的情况下 ...
- Zookeeper客户端链接
一.zkCli.sh ./zkCli.sh -server 39.97.176.160:2182 39.97.176.160 : zookeeper服务器Ip 2182:zookeeper端口 二.Z ...
- 【Linux】【Services】任务计划、周期性任务执行
Linux任务计划.周期性任务执行 未来的某时间点执行一次某任务:at, batch 周期性运行某任务:crontab 执行结果:会通过邮件发送给用户 ...
- 【Java 8】Stream通过reduce()方法合并流为一条数据示例
在本页中,我们将提供 Java 8 Stream reduce()示例. Stream reduce()对流的元素执行缩减.它使用恒等式和累加器函数进行归约. 在并行处理中,我们可以将合并器函数作为附 ...
- 【C/C++】习题3-7 DNA/算法竞赛入门经典/数组与字符串
[题目] 输入m组n长的DNA序列,要求找出和其他Hamming距离最小的那个序列,求其与其他的Hamming距离总和. 如果有多个序列,求字典序最小的. [注]这道题是我理解错误,不是找出输入的序列 ...