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 题目大意:给你一片森林,要求你在一些节点上放上灯,一个点放灯能照亮与之相连的所有的 ...
随机推荐
- 多线程(七)JDK原生线程池
如同数据库连接一样,线程的创建.切换和销毁同样会耗费大量的系统资源.为了复用创建好的线程,减少频繁创建线程的次数,提高线程利用率可以引用线程池技术.使用线程池的优势有如下几点: 1.保持 ...
- C# 反射、与dynamic最佳组合
在 C# 中反射技术应用广泛,至于什么是反射.........你如果不了解的话,请看下段说明,否则请跳过下段.广告一下:希望我文章的朋友请关注一下我的blog,这也有助于提高本人写作的动力. 反射:当 ...
- Python Counter class
Counter class https://docs.python.org/2/library/collections.html#collections.Counter # class collect ...
- 深入剖析ConcurrentHashMap二
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt200 我们关注的操作有:get,put,remove 这3个操作.对于哈希表 ...
- webarchive文件转换成htm文…
原文地址:webarchive文件转换成htm文件作者:xhbaxf Mac OS X系统带有文件转换功能,可以把webarchive文件变成html文件.方法是: Step 1: 建立一个文件夹 ...
- 201521123119《Java程序设计》第4周学习总结
1. 本周学习总结 2.书面作业 1.注释的应用 使用类的注释与方法的注释为前面编写的类与方法进行注释,并在Eclipse中查看.(截图) 2.面向对象设计(大作业1,非常重要) 2.1 将在网上商城 ...
- 201521145048《Java程序设计管理》第一周学习总结
1. 本周学习总结 学习并了解Java的发展与历史 在网上视频中学习Java 了解并区分JVM JRE JDK 将java与已学语言做比较,发现相同处 2. 书面作业 Q1.为什么java程序可以跨平 ...
- 201521123093 java 第十四周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. MySQL中的库操作和表操作 库操作: 显示所有数据库: show databases; 创建数据库: crea ...
- 201521123032 《Java程序设计》第13周学习总结
1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 书面作业 1. 网络基础 1.1 比较ping www.baidu.com与ping cec.jmu ...
- 看懂类图——UML类图基础
类图 要学懂设计模式,就需要先看得懂类图,类与类之间的关系是学习设计模式的基础,而在软件工程中,类与类之间的关系是通过UML中的类图来体现. 这篇笔记包含的不会是类图的所有东西,包含的只是各个类之间的 ...