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 题目大意:给你一片森林,要求你在一些节点上放上灯,一个点放灯能照亮与之相连的所有的 ...
随机推荐
- 关于idea的使用心得
开发java多年,所在的项目组一直都在使用的eclipse或者myeclipse,今天偶然的机会接触到了idea,感觉优化的确实不错,下面是我的一些使用心得:
- github开源项目学习-front-end-collect
About 项目地址 项目预览demo(githubio加载较慢) 开源项目fork自:https://github.com/foru17/front-end-collect 此文章是对此开源项目使用 ...
- 神奇的background
background:url() fixed .... 可以实现页面向下滚动时背景图片 保持位置不变 感觉好像背景在随鼠标滚动而滚动一样
- 使用 PUTTY 操作 Google Cloud
目的: 使用putty连接Google Cloud 实例. 总说: 首先要用 PuTTYgen生成 private key 和 public key, 之后 登录Google Cloud 将生成的 ...
- 改变input光标颜色与输入字体颜色不同
设置input css: color #ffd600text-shadow 0px 0px 0px #bababa -webkit-text-fill-color initial input, tex ...
- vue中引入swiper(vue中的滑块组件vue-awesome-swiper)
第一步安装 npm install vue-awesome-swiper --save 第二部在main.js中引入 import VueAwesomeSwiper from 'vue-awesome ...
- display:inline-block间隙问题
display:inline-block 是让块级元素变成行内元素 在一行显示, 然而不幸的是,它并没有得到所有浏览器的支持,比如ie6.7和古老一点的firefox完全无视它,由于firefox的老 ...
- Ubuntu操作系统下安装JDK、tomcat、mysql
1.先从安装虚拟机开始 01.首先打开VMware虚拟机. 02.然后,进入home主页,点击"create a New Virtual Machine"一栏,就会弹出一个 ...
- YYHS-怎样更有力气
题目描述 OI大师抖儿在夺得银牌之后,顺利保送pku.这一天,抖儿问长者:"我虽然已经保送了,但我的志向是为国家健康工作五十年.请问我应该怎样变得更有力气?" 长者回答:&quo ...
- 201521123122 《java程序设计》第八周实验总结
201521123122 <java程序设计>第八周实验总结 1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 List中指定元素的删除(题目4- ...