How many Knight Placing? UVA - 11091
Time Limit: 3000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
Description
I I U P C 2 0 0 6 |
|
Problem H: How many Knight Placing? |
|
Input: standard input Output: standard output |
|
You are given a 6*n chessboard. Yes it is not a regular chessboard. The number of columns in this chessboard is variable. In each of the columns you have to place exactly 2 knights. So you have to place total 2*n knights. You have to count the number of valid placing of these 2*n knight. A placing is invalid if any of the 2 knights attack each other. Those who are not familiar with knight moves “A knight in cell(x,y) attacks the knights in the cell(x±2,y±1) and cell(x±1,y±2)”. |
|
Input |
|
The first line of the input contains a single integer T indicating the number of test cases. Each test case contains a single integer n. |
|
Output |
|
For each test case output an integer the number of valid placing. The integer may be very large. So just output the result%10007. |
|
Constraints |
|
- T ≤ 15 |
|
Sample Input |
Output for Sample Input |
4 |
15 |
好恶心的矩阵构造啊!
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define mod 10007
typedef struct point
{
int x,y;
} point;
typedef struct mar
{
int a[][];
} mar;
mar ri,anss,riri;
point p[];
int a[];
int check(int t)
{
int sum=;
while(t)
{
if(t&)sum++;
t>>=;
}
return sum==;
}
bool fun(int x,int y)
{
if((x<<)&y||(y<<)&x)return ;
return ;
}
bool fun1(int x,int y,int z)
{
if(!fun(x,y)||!fun(y,z))return ;
if((x<<)&z||(z<<)&x)return ;
return ;
}
mar mul(mar x,mar y)
{
mar z;
memset(z.a,,sizeof(z.a));
int i,j,k;
for(k=; k<; k++)
for(i=; i<; i++)
if(x.a[i][k])
for(j=; j<; j++)
z.a[i][j]+=x.a[i][k]*y.a[k][j]%mod,z.a[i][j]%=mod;
return z;
}
void init()
{
int tt=(<<)-,nu=,i,j;
while(tt)
{
if(check(tt))
a[nu++]=tt;
tt--;
}
nu=;
for(i=; i<; i++)
for(j=; j<; j++)
if(fun(a[i],a[j]))
p[nu].x=a[i],p[nu++].y=a[j];
memset(ri.a,,sizeof(ri.a));
for(i=; i<; i++)
{
for(j=; j<; j++)
{
if(p[i].y==p[j].x)
{
if(fun1(p[i].x,p[i].y,p[j].y))
ri.a[i][j]=;
}
}
}
}
int solve(int m)
{
int i,j,ans=;
memset(anss.a,,sizeof(anss.a));
memset(riri.a,,sizeof(riri.a));
for(i=; i<; i++)anss.a[i][i]=;
for(i=; i<; i++)
for(j=; j<; j++)riri.a[i][j]=ri.a[i][j];
m-=;
while(m)
{
if(m&)
anss=mul(anss,riri);
riri=mul(riri,riri);
m>>=;
}
for(i=; i<; i++)
for(j=; j<; j++)ans+=anss.a[i][j],ans%=mod;
return ans;
}
int main()
{
init();
int t,m;
scanf("%d",&t);
while(t--)
{
scanf("%d",&m);
if(m==)
{
printf("15\n");
continue;
}
else if(m==)
{
printf("69\n");
continue;
}
printf("%d\n",solve(m));
}
}
How many Knight Placing? UVA - 11091的更多相关文章
- Knight Moves UVA - 439
A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the sh ...
- 10_放置街灯(Placing Lampposts,UVa 10859)
问题来源:刘汝佳<算法竞赛入门经典--训练指南> P70 例题30: 问题描述:有给你一个n个点m条边(m<n<=1000)的无向无环图,在尽量少的节点上放灯,使得所有边都被照 ...
- UVA 439 Knight Moves(BFS)
Knight Moves option=com_onlinejudge&Itemid=8&category=11&page=show_problem&problem=3 ...
- UVA 439 Knight Moves --DFS or BFS
简单搜索,我这里用的是dfs,由于棋盘只有8x8这么大,于是想到dfs应该可以过,后来由于边界的问题,TLE了,改了边界才AC. 这道题的收获就是知道了有些时候dfs没有特定的边界的时候要自己设置一个 ...
- UVA 439 Knight Moves
// 题意:输入标准国际象棋棋盘上的两个格子,求马最少需要多少步从起点跳到终点 BFS求最短路: bfs并维护距离状态cnt, vis记录是否访问过 #include<cstdio> ...
- UVA Knight Moves
题目例如以下: Knight Moves A friend of you is doing research on the Traveling Knight Problem (TKP) where ...
- UVa 10859 - Placing Lampposts 树形DP 难度: 2
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- 【UVa】439 Knight Moves(dfs)
题目 题目 分析 没有估价函数的IDA...... 代码 #include <cstdio> #include <cstring> #include <a ...
- UVA - 10859 Placing Lampposts 放置街灯
Placing Lampposts 传送门:https://vjudge.net/problem/UVA-10859 题目大意:给你一片森林,要求你在一些节点上放上灯,一个点放灯能照亮与之相连的所有的 ...
随机推荐
- EAGO科技人工智能+澳洲MSPL外汇平台招商
天下财经 首席运营商 EAGO外汇人工智能简介:我们将历史数据导入算法引擎,加入因子(外汇中使用的各种技术指标及各个国家的货币政策等)让计算机通过二元遗传基因.深度神经网络等算法,由机器自主深度学习. ...
- 又想起Solaris
想起曾几何时,学习的第一个UNIX-like操作系统.只可惜,从来都是在此操作系统上用C语言编程,而没有用过Sun公司的java. 又几何时,Sun公司慢慢不行了.再后来过了几年,Sun公司把Ultr ...
- Grails笔记一:windows8.1操作系统cmd下grails命令无效
最近决定使用intellij idea工具来开发基于Grails框架的应用程序,,在安装好jdk 1.7以及配置好jdk和grails环境变量后进行grails测试,在win8.1的命令行窗口中输入以 ...
- win10下移动硬盘位置不可用无法访问
win10下移动硬盘位置不可用无法访问 网上搜索得到的答案是: 请参考以下步骤解决: 1.按Windows+R输入"CHKDSK H: /F /R"(H:是硬盘所在盘符./R 找到 ...
- 性能测试中vmstat命令的常见使用。
vmstat是Linux中常用的一个命令,尤其是在进行性能测试时,使用该命令,往往能辅助我们进行性能问题定位. 我们先看一下这个命令执行得到的数据. [root@xxx ~]# vmstat 1 10 ...
- AFN和SDWebImage请求网络图片的一点问题
问题1.AFN 处理有关图片相关的请求的问题 在使用AFN Post网络图片的时候发现NSLocalizedDescription=Request failed: unacceptable conte ...
- main方法快速编辑日历
public static void main(String[] args) { Scanner input=new Scanner (System.in); System.out.println(& ...
- 换个角度审视NAT技术
NAT (Network address translation,网络地址转换 )是局域网连接到互联网的一个对接工作. 首先要知道NAT是一个技术或者说软件而不是协议 后面你会知道NAT 是偏应用层但 ...
- socket和抓包工具wireshark
socket和抓包工具wireshark 最近在学习Python代码中的socket和抓包工具wireshark,故又将socket等概念又学习了一遍,温故而知新: Python代码如下: serve ...
- 【Socket编程】Java通信是这样炼成的
简介 网络无处不在,移动互联时代也早已到来,单机版程序慢慢的已没有生命力,所有的程序都要能够访问网络,比如 QQ 网络聊天程序.迅雷下载程序等,这些程序都要同网络打交道,本次将与各位小伙伴们分享的就是 ...