2017 ICPC 广西邀请赛1004 Covering
Covering
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 187 Accepted Submission(s): 107
To protect boys and girls from getting hurt when playing happily on the playground, rich boy Bob decided to cover the playground using his carpets.
Meanwhile, Bob is a mean boy, so he acquired that his carpets can not overlap one cell twice or more.
He has infinite carpets with sizes of 1×2 and 2×1, and the size of the playground is 4×n.
Can you tell Bob the total number of schemes where the carpets can cover the playground completely without overlapping?
Each test case only contains one positive integer n in a line.
1≤n≤1018
2
5
/*
* @Author: Administrator
* @Date: 2017-08-31 17:40:04
* @Last Modified by: Administrator
* @Last Modified time: 2017-09-01 11:03:00
*/
/*
题意:给你一个4*n的矩阵,然后让你用1*2和2*1的木块放,问你完美覆盖的
方案数 思路:状压DP找规律
*/ #include <bits/stdc++.h> #define MAXN 100
#define MAXM 20
#define MAXK 15
using namespace std; int dp[MAXN][MAXM];//dp[i][j]表示前ihang
int n; inline bool ok(int x){
//判断是不是有连续个1的个数是奇数
int res=;
while(x){
if(x%==){
res++;
}else{
if(res%==) return false;
else res=;
}
x/=;
}
if(res%==) return false;
else return true;
} inline void init(){
memset(dp,,sizeof dp);
} int main(){
freopen("in.txt","r",stdin);
for(int n=;n<=;n++){
init();
for(int i=;i<=MAXK;i++){//初始化第一行的没种状态
if(ok(i)==true)
dp[][i]=;
}
for(int i=;i<n;i++){
for(int j=;j<=MAXK;j++){
if(dp[i][j]!=){
for(int k=;k<=MAXK;k++){
if( (j|k)==MAXK && ok(j&k) )
///j|k==tot-1的话就是能拼起来组成
dp[i+][k]+=dp[i][j];
}
}
}
}
printf("%d\n",dp[n][MAXK]);
}
return ;
}
/*
* @Author: Administrator
* @Date: 2017-09-01 11:17:37
* @Last Modified by: Administrator
* @Last Modified time: 2017-09-01 11:28:09
*/
#include <bits/stdc++.h> #define MAXN 5
#define mod 1000000007
#define LL long long using namespace std; /********************************矩阵快速幂**********************************/
class Matrix {
public:
LL a[MAXN][MAXN];
LL n; void init(LL x) {
memset(a,,sizeof(a));
if (x)
for (int i = ; i < MAXN ; i++)
a[i][i] = 1LL;
} Matrix operator +(Matrix b) {
Matrix c;
c.n = n;
for (int i = ; i < n; i++)
for (int j = ; j < n; j++)
c.a[i][j] = (a[i][j] + b.a[i][j]) % mod;
return c;
} Matrix operator +(LL x) {
Matrix c = *this;
for (int i = ; i < n; i++)
c.a[i][i] += x;
return c;
} Matrix operator *(Matrix b)
{
Matrix p;
p.n = b.n;
p.init();
for (int i = ; i < n; i++)
for (int j = ; j < n; j++)
for (int k = ; k < n; k++)
p.a[i][j] = (p.a[i][j] + (a[i][k]*b.a[k][j])%mod) % mod;
return p;
} Matrix power(LL t) {
Matrix ans,p = *this;
ans.n = p.n;
ans.init();
while (t) {
if (t & )
ans=ans*p;
p = p*p;
t >>= ;
}
return ans;
}
}init,unit;
/********************************矩阵快速幂**********************************/ LL n; int main(){
// freopen("in.txt","r",stdin);
while(scanf("%lld",&n)!=EOF){
if(n<=){
switch(n){
case :
puts("");
break;
case :
puts("");
break;
case :
puts("");
break;
case :
puts("");
break;
}
continue;
}
init.init();
init.n=;
init.a[][]=;
init.a[][]=;
init.a[][]=;
init.a[][]=;
unit.init();
unit.n=;
unit.a[][]=;
unit.a[][]=;
unit.a[][]=;
unit.a[][]=-;
unit.a[][]=;
unit.a[][]=;
unit.a[][]=;
unit=unit.power(n-);
init=init*unit;
printf("%lld\n",(init.a[][]+mod)%mod);
}
return ;
}
2017 ICPC 广西邀请赛1004 Covering的更多相关文章
- 2017ACM/ICPC广西邀请赛 1004 Covering
Covering Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 2017 ICPC 广西邀请赛1005 CS Course
CS Course Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 2017ACM/ICPC广西邀请赛-重现赛 1004.Covering
Problem Description Bob's school has a big playground, boys and girls always play games here after s ...
- 2017 ACM/ICPC 广西邀请赛 题解
题目链接 Problems HDOJ上的题目顺序可能和现场比赛的题目顺序不一样, 我这里的是按照HDOJ的题目顺序来写的. Problem 1001 签到 #include <bits/std ...
- 2017ACM/ICPC广西邀请赛-重现赛(感谢广西大学)
上一场CF打到心态爆炸,这几天也没啥想干的 A Math Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/3 ...
- 2017ACM/ICPC广西邀请赛-重现赛 1007.Duizi and Shunzi
Problem Description Nike likes playing cards and makes a problem of it. Now give you n integers, ai( ...
- 2017ACM/ICPC广西邀请赛-重现赛 1010.Query on A Tree
Problem Description Monkey A lives on a tree, he always plays on this tree. One day, monkey A learne ...
- 2017ACM/ICPC广西邀请赛-重现赛
HDU 6188 Duizi and Shunzi 链接:http://acm.hdu.edu.cn/showproblem.php?pid=6188 思路: 签到题,以前写的. 实现代码: #inc ...
- HDU 6191 2017ACM/ICPC广西邀请赛 J Query on A Tree 可持久化01字典树+dfs序
题意 给一颗\(n\)个节点的带点权的树,以\(1\)为根节点,\(q\)次询问,每次询问给出2个数\(u\),\(x\),求\(u\)的子树中的点上的值与\(x\)异或的值最大为多少 分析 先dfs ...
随机推荐
- 从Leetcode的Combination Sum系列谈起回溯法
在LeetCode上面有一组非常经典的题型--Combination Sum,从1到4.其实就是类似于给定一个数组和一个整数,然后求数组里面哪几个数的组合相加结果为给定的整数.在这个题型系列中,1.2 ...
- Spring Boot Document Part II(上)
Part II. Getting started 这一章内容适合刚接触Spring Boot或者"Spring"家族的初学者!随着安装指导说明,你会发现对Spring boot有一 ...
- Javascript写的一个可拖拽排序的列表
自己常试写了一个可拖拽进行自定义排序的列表,可能写的不太好,欢迎提供意见. 我的思路是将列表中的所有项都放进一个包裹层,将该包裹层设为相对定位,每当点击一个项时,将该项脱离文档并克隆一份重新添加到文档 ...
- D. How many trees? DP
D. How many trees? time limit per test 1 second memory limit per test 64 megabytes input standard in ...
- 管中窥豹——从OVS看SDN
网络虚拟化是当前云计算最重要的特点之一,打通租户网络之间互通以及访问控制策略,最重要的是满足租户之间的网络隔离,这才是云计算网络的特点.而SDN的产生则是在网络虚拟化中,将控制面和业务面分离,控制面只 ...
- vue2组件之select2调用
目前,项目中使用了纯前端的静态项目+RESTFul接口的模式.为了更好的对数据进行操作,前端使用了vue2的mvvm功能,但是由于不是单页面应用,所以,并没有涉及到其它的如vue-route等功能,也 ...
- C-一行或多行文章垂直居中
1 样式效果 2 table布局 li span
- Jquery使用mouseenter和mouseleave实现鼠标经过弹出层且可以点击
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Jquery使用mousee ...
- 【学习】ie8支持rgba()透明度颜色
(我的博客网站中的原文:http://www.xiaoxianworld.com/archives/285,欢迎遇到的小伙伴常来瞅瞅,给点评论和建议,有错误和不足,也请指出.) rgba()函数可以用 ...
- 通过VBA,当在EXCEL单元格中输入任意的日期格式时,都能自动转换为指定的标准格式的日期值
在日常录入EXCEL表格的单元格里 ,我们输入一些一般性的日期内容,如:2017-10-17 或 2017/10/17时,EXCEL会自动识别为日期并按单元格设计格式显示,单元格中存储的值也是日期格式 ...